How to confirm Android Share Intent is successful or complete

假装没事ソ 提交于 2019-12-10 03:54:18

问题


Is there a way to confirm if a Share intent in Android was successful or unsuccessful? (For example, if I share a Facebook post, I'd like to know if it was successfully posted or know if it was cancelled.)

Below is the Android intent code that I use to Share. Currently, it launches a dialog to allow the user to choose which app to share to:

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);    
activity.startActivity(Intent.createChooser(shareIntent, title));

回答1:


Personally, I was about to say "use startActivityForResult()" and check what gets returned. However, as you can read more here, it's not as simple as that. If the intent is cancelled by the user, the same number is returned as if the intent was completed (for most appications).

Ultimately, at the moment for a simpler Share intent in general, you cannot check if it's successful or not.




回答2:


In case of FacebookShareDialog Build your dialog with requestCode then onActivity check the Request code and Result code. For this there is one class in Facebook Sdk Name UiLifecycleHelper

in onCreate Method

uiHelper = new UiLifecycleHelper(this, null);
uiHelper.onCreate(savedInstanceState);




 FacebookDialog fbShardialog = new FacebookDialog.ShareDialogBuilder(
                        MainActivity.this)
                        .setLink("http://www.claro.com.ar/")
                        .setPicture("imagepath").setRequestCode(12)
                        .build();

                uiHelper.trackPendingDialogCall(fbShardialog.present());



OnActivityResult


 if (requestCode == 12) {
        if (resultCode == RESULT_OK) {
            //  show sucess message

        }
 else
//show failure message

    }


来源:https://stackoverflow.com/questions/27241227/how-to-confirm-android-share-intent-is-successful-or-complete

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!