We will encounter interactions with other applications during development. The following is a simple method. The overall usage is similar to "using intent to call the built-in photo app and get the results ".
First look at the page:
Let's take a look at the implementation steps.
The first application DEMO1:
1. Create a custom action and send it using intent
String action = "zyf.demo.customAction"; Intent n = new Intent(action);
2. Add custom content in the attachment, and use putExtra
N. putExtra ("key1", "hello, this is the message from demo1. ");
3. check whether there is content matching this action first.
String action = "zyf. demo. customAction "= Intent intent = <ResolveInfo> resolveInfo = (resolveInfo. size ()> 0 "matching activity found", 0 "no matching activity found", 0
4. Use startActivityForResult to start Intent.
StartActivityForResult (n, REQUEST_CODE_1 );
5. Get the result (from DEMO2)
Final int REQUEST_CODE_1 = 1; @ Overrideprotected void onActivityResult (int requestCode, int resultCode, Intent data) {if (requestCode = REQUEST_CODE_1) {String res = data. getStringExtra ("result"); Toast. makeText (getBaseContext (), "Received:" + res, 0 ). show ();} elsesuper. onActivityResult (requestCode, resultCode, data );}
The second application, DEMO2:
1. Create an activity to receive the action specified above and register intent-filter in the AndroidManifest. xml file.
<="zyf.demo.demo2.MainActivity"="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
2. Data from DEMO1 can be displayed in the activity.
== intent.getStringExtra("key1"
3. process the returned content when the current application is disabled in the activity.
= "Result", "this is the result from demo2"
This is done. DEMO code download