Engineering structure
//
Click Test Share Click Createch Oose Magical
The main thing is to see the right, not with what dialog to do, but you activity program, you can activate in
Hint: This thing can be extended to an audio file, when opened, can call your music player to play Oh, video, picture, is also similar, can call your own things
Of course, the premise is that your manifest.xml is going to be configured right.
<data android:mimetype= "Mark/nimei"/>
As follows
<activity android:name= ". Testactivity "
Android:label=, "Your sister."
>
<intent-filter>
<action android:name= "Android.intent.action.XXMM"/>
<category android:name= "Android.intent.category.DEFAULT"/>
<category android:name= "Android.intent.category.OPENABLE"/>
<data android:mimetype= "Mark/nimei"/>
</intent-filter>
</activity>
<activity android:name= ". Test2activity "
Android:label=, "Your sister, 2."
>
<intent-filter>
<action android:name= "Android.intent.action.XXMM"/>
<category android:name= "Android.intent.category.DEFAULT"/>
<category android:name= "Android.intent.category.OPENABLE"/>
<data android:mimetype= "Mark/nimei"/>
</intent-filter>
</activity>
The code is as follows:
[Java]View plain copy
- Package Com.mark.share.demo;
- Import Java.io.File;
- Import android.app.Activity;
- Import android.content.Intent;
- Import Android.net.Uri;
- Import Android.os.Bundle;
- Import Android.view.View;
- Import Android.view.View.OnClickListener;
- Import Android.widget.Button;
- Public class Appsharedemoactivity extends Activity
- {
- private Button TestShare;
- private Button createchooserbtn;
- @Override
- public void OnCreate (Bundle savedinstancestate)
- {
- super.oncreate (savedinstancestate);
- Setcontentview (R.layout.main);
- Testshare= (Button) Findviewbyid (R.id.testshare);
- Createchooserbtn= (Button) Findviewbyid (R.id.test_createchooser);
- Testshare.setonclicklistener (new Onclicklistener ()
- {
- @Override
- public void OnClick (View v)
- {
- Intent Intent = new Intent (intent.action_send);
- Intent.setflags (Intent.flag_activity_new_task);
- Intent.putextra (Intent.extra_stream, Uri.fromfile (new File ("sdcard/1.png")); //Transfer pictures or files in a streaming manner
- Intent.putextra (Intent.extra_text, "share and share micro-blog"); //Description information included
- Intent.putextra (Intent.extra_subject, "title");
- Intent.settype ("image/*"); //share pictures
- StartActivity (Intent.createchooser (Intent,"share"));
- }
- });
- Createchooserbtn.setonclicklistener (new Onclicklistener ()
- {
- @Override
- public void OnClick (View v)
- {
- Intent Intent = new Intent ();
- Intent.setflags (Intent.flag_activity_new_task);
- Intent.setaction ("Android.intent.action.XXMM");
- Intent.setdataandtype (Uri.parse ("File:///sdcard/DCIM/cc.mp3"), "Mark/nimei");
- StartActivity (Intent.createchooser (Intent, "select Music1 App"));
- }
- });
- }
- }
Android call system sharing function and Createchooser use