Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
24.7k views
in Technique[技术] by (71.8m points)

email - Android: Share plain text using intent (to all messaging apps)

I'm trying to share some text using an intent:

Intent i = new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/plain");  
i.putExtra(android.content.Intent.EXTRA_TEXT, "TEXT");

and warping with chooser:

startActivity(Intent.createChooser(sms, getResources().getString(R.string.share_using)));

it works! but only for email app.
what I need is a general intent for all messaging app: emails, sms, IM (Whatsapp, Viber, Gmail, SMS...) tried using android.content.Intent.ACTION_VIEW and tried using i.setType("vnd.android-dir/mms-sms"); nothing helped...

("vnd.android-dir/mms-sms" shared using sms only!)

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use the code as:

    /*Create an ACTION_SEND Intent*/
    Intent intent = new Intent(android.content.Intent.ACTION_SEND);
    /*This will be the actual content you wish you share.*/
    String shareBody = "Here is the share content body";
    /*The type of the content is text, obviously.*/
    intent.setType("text/plain");
    /*Applying information Subject and Body.*/
    intent.putExtra(android.content.Intent.EXTRA_SUBJECT, getString(R.string.share_subject));
    intent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
    /*Fire!*/
    startActivity(Intent.createChooser(intent, getString(R.string.share_using)));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...