HTTP://BLOG.CSDN.NET/XYZ_LMN/ARTICLE/DETAILS/16856843 uses the intent implicit invoke activity method, mainly uses the Intent.action_ Send and Intent.createchooser (); Call the share interface of the Android system. The system filters the apps on the phone with the sharing app, giving the user a choice. If you do not use Intent.createchooser () then the system will be the default user sharing method, only if not set up to let the user choose. 1.simple sharing of text
1 New Intent (); 2 intent.setaction (intent.action_send); // set the action of the intent 3 Intent.putextra (Intent.extra_text, "YOUR SHARE TEXT"); // what to share tag and content 4 intent.settype ("Text/plain"); // the type of data sent by the flag for easy processing by the receiver (type/subtype) 5 startactivity (Inten); // using methods that implicitly invoke activity
- Methods for implicitly invoking activity
Or
- StartActivity (Intent.createchooser (Intent, "TheChooser dialog title");//
2.send pictures using the
- Intent.putextra (Intent.extra_stream, Imageuri);
- Intent.settype ("imag/*");//* can be jpg,png, etc.
3.You can also share a set of data at the same time
1 list<uri> URIs; 2 New Intent (); 3 intent.setaction (intent.action_sed_multiple); // Send Group 4 Intent.putparcelablearraylistextra (Intent.extra_stream, URIs); 5 intent.settype ("*/*");//If all are video videos/*6startactivity (intent);
If you want your app to go to the pop-up share list, you'll need to add intent-filter to the Mainifest:Example:
1 <Intent-filter> 2 <ActionAndroid:name= "Android.intent.action.SEND" /> 3 4 <categoryAndroid:name= "Android.intent.category.DEFAULT" /> 5 6 <DataAndroid:mimetype= "image/*" /> 7 </Intent-filter> 8 <Intent-filter> 9 <ActionAndroid:name= "Android.intent.action.SEND" /> Ten One <categoryAndroid:name= "Android.intent.category.DEFAULT" /> A - <DataAndroid:mimetype= "Text/plain" /> - </Intent-filter> the <Intent-filter> - <ActionAndroid:name= "Android.intent.action.SEND_MULTIPLE" /> - - <categoryAndroid:name= "Android.intent.category.DEFAULT" /> + - <DataAndroid:mimetype= "image/*" /> + </Intent-filter>
Received in the activity received
1 Intent Intent = getintent (); 2 String action = intent.getaction (); // corresponding intent.setaction () 3 String type = Intent.gettype (); // corresponding Intent.settype () 4 Inten.get??? Extra (Intent.extra_???) or Intent.getparcelableextra (Intent.extra_stream);
You can also put the share in the Actionbar.