首页 > 代码库 > Android Intent
Android Intent
1. make a app as browser, register in AndroidManifest.xml
<intent-filter> <action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.BROWSABLE"/> <category android:name="andoid.intent.category.DEFAULT" /> <data android:scheme="http"/> </intent-filter>
http://blog.vogella.com/2011/02/21/android-intents/ Registering for Android Intents – Being a crappy browser
2. start another activity
Intent intent = null;intent = new Intent(CurrentActivity.this, AnotherActivity.class);startActivity(intent);
3. start activity for result
static private final int GET_TEXT_REQUEST_CODE = 1;// TODO - Start an Activity using that intent and the request code defined above
Intent explicitIntent = new Intent(CurrentActivity.this,AnotherActivity.class);
startActivityForResult(explicitIntent, GET_TEXT_REQUEST_CODE);
this method onActivityResult() will be called after AnotherActivity return(finish)
@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data)
in AnotherActivity: set result and finish
Intent intent = new Intent();intent.putExtra("hello", input);this.setResult(RESULT_OK, intent);finish();
4. create chooser, let user select from a list of app to handle this request
Intent baseIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));Intent chooserIntent = Intent.createChooser(baseIntent, CHOOSER_TEXT);startActivity(chooserIntent);
5. start another application
in current application
startActivity(new Intent("course.labs.permissions.DANGEROUS_ACTIVITY"));
in another application‘s AndroidManifest.xml
<intent-filter> <action android:name="course.labs.permissions.DANGEROUS_ACTIVITY" /> <category android:name="android.intent.category.DEFAULT" /></intent-filter>
Android Intent
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。