Callback from chooser

2019-08-26 22:09发布

问题:

I just started implementing a share functionality but was wondering if its possible to tell how my content was shared (facebook/twitter/text/etc) without writing my own implementation of chooser. My initial guess was to use startActivityForResult when launching the chooser but haven't managed to figure out which requestcode to use.

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)));
}

Any help would be greatly appreciated! :)

回答1:

My initial guess was to use startActivityForResult when launching the chooser but haven't managed to figure out which requestcode to use.

That will not work reliably. ~99% of activities are not set up to work with startActivityForResult.

I just started implementing a share functionality but was wondering if its possible to tell how my content was shared (facebook/twitter/text/etc) without writing my own implementation of chooser

Sorry, you will need to write your own chooser for this.