Android call system sharing function and Createchooser use

Source: Internet
Author: User

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
  1. Package Com.mark.share.demo;
  2. Import Java.io.File;
  3. Import android.app.Activity;
  4. Import android.content.Intent;
  5. Import Android.net.Uri;
  6. Import Android.os.Bundle;
  7. Import Android.view.View;
  8. Import Android.view.View.OnClickListener;
  9. Import Android.widget.Button;
  10. Public class Appsharedemoactivity extends Activity
  11. {
  12. private Button TestShare;
  13. private Button createchooserbtn;
  14. @Override
  15. public void OnCreate (Bundle savedinstancestate)
  16. {
  17. super.oncreate (savedinstancestate);
  18. Setcontentview (R.layout.main);
  19. Testshare= (Button) Findviewbyid (R.id.testshare);
  20. Createchooserbtn= (Button) Findviewbyid (R.id.test_createchooser);
  21. Testshare.setonclicklistener (new Onclicklistener ()
  22. {
  23. @Override
  24. public void OnClick (View v)
  25. {
  26. Intent Intent = new Intent (intent.action_send);
  27. Intent.setflags (Intent.flag_activity_new_task);
  28. Intent.putextra (Intent.extra_stream, Uri.fromfile (new File ("sdcard/1.png")); //Transfer pictures or files in a streaming manner
  29. Intent.putextra (Intent.extra_text, "share and share micro-blog"); //Description information included
  30. Intent.putextra (Intent.extra_subject, "title");
  31. Intent.settype ("image/*"); //share pictures
  32. StartActivity (Intent.createchooser (Intent,"share"));
  33. }
  34. });
  35. Createchooserbtn.setonclicklistener (new Onclicklistener ()
  36. {
  37. @Override
  38. public void OnClick (View v)
  39. {
  40. Intent Intent = new Intent ();
  41. Intent.setflags (Intent.flag_activity_new_task);
  42. Intent.setaction ("Android.intent.action.XXMM");
  43. Intent.setdataandtype (Uri.parse ("File:///sdcard/DCIM/cc.mp3"), "Mark/nimei");
  44. StartActivity (Intent.createchooser (Intent, "select Music1 App"));
  45. }
  46. });
  47. }
  48. }

Android call system sharing function and Createchooser use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.