How to get callback of ACION_SEND Intent

2020-02-15 08:44发布

I tried this

 private void postImage(Uri uri) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_SEND);
            intent.setType("image/*");
            intent.addCategory(Intent.CATEGORY_DEFAULT);
            intent.putExtra(Intent.EXTRA_TEXT, "My bracelet image");
            intent.putExtra(Intent.EXTRA_TITLE, "Action Bracelet");
            intent.putExtra(Intent.EXTRA_STREAM,uri);
            Intent chooser=Intent.createChooser(intent,"Share Image Using");
            try{
            context.startActivity(chooser);
            }
            catch(ActivityNotFoundException e){
                Toast.makeText(context,"You don't have any share application installed",Toast.LENGTH_SHORT).show();
                Log.e("Image Load","failed");
            }
        }

Now my problem is i need the application name on which this image is shared .I also created my custom dialog for it but problem remains same . Because when i select an option for share like facebook and i pressed back button then image is not share and i only know that the user click on facebook. so i need a callback which gives me result_ok and result_cancle and the application name too . Can anyone help me i am stuck here from last three days ...

1条回答
闹够了就滚
2楼-- · 2020-02-15 09:05

Now my problem is i need the application name on which this image is shared

If your minSdkVersion is 22 or higher, use the createChooser() that takes an IntentSender as the third parameter, as that is your only means of finding out what the user chose.

If your minSdkVersion is below 22, you will have to create your own chooser-style UI, using PackageManager and queryIntentActivities() to find out what activities should be listed in that UI.

I also created my custom dialog for it but problem remains same

You certainly know what the user chose in the dialog. That is all you are going to get from the API Level 22 createChooser() either.

Because when i select an option for share like facebook and i pressed back button then image is not share and i only know that the user click on facebook.

Of course. The user can do whatever the user wants in that other application. The user does not have to press BACK; the user can simply fail to send anything. That is between the user and that application — information about whether the user did anything, who the user shared the information with, and so on, is not available to you.

查看更多
登录 后发表回答