Android share intent chooser

2019-01-22 09:08发布

I am using something like this to share some text using available applications on the user's phone.

public void share(String subject,String text) {
     final Intent intent = new Intent(Intent.ACTION_SEND);

     intent.setType("text/plain");
     intent.putExtra(Intent.EXTRA_SUBJECT, subject);
     intent.putExtra(Intent.EXTRA_TEXT, text);

     startActivity(Intent.createChooser(intent, getString(R.string.share)));
}

My main problem is that I would like to have a different text if the user chooses Twitter instead of email for example (short version with short URLs VS full text with attached images).

How can ont find out which application the user has decided to use?

2条回答
霸刀☆藐视天下
2楼-- · 2019-01-22 09:18

Once you hand the text off to the system with createChooser its out of your hands, no way to change the text after that.

查看更多
放荡不羁爱自由
3楼-- · 2019-01-22 09:38
 Intent intent = new Intent(Intent.ACTION_SEND);

 intent.setType("text/plain");
 intent.putExtra(Intent.EXTRA_SUBJECT, subject);
 intent.putExtra(Intent.EXTRA_TEXT, textWhichYouWantToShare);

 startActivity(Intent.createChooser(intent, getString(R.string.share)));
查看更多
登录 后发表回答