Using share dialog in Android Facebook SDK. How to know is user actually shared or cancelled sharing activity?

前端 未结 6 2114
無奈伤痛
無奈伤痛 2021-01-11 09:41

I have added sharing functionality to Android app as described here https://developers.facebook.com/docs/android/share-dialog/#setup

But I have noticed that if user

6条回答
  •  -上瘾入骨i
    2021-01-11 10:15

    Heading ## private static ShareDialog shareDialog;

        private static FacebookCallback shareCallback = new FacebookCallback() {
            @Override
            public void onCancel() {
                Log.d("HelloFacebook", "Canceled");
            }
    
            @Override
            public void onError(FacebookException error) {
                Log.d("HelloFacebook", String.format("Error: %s", error.toString()));
                String title = this.getActivty().getString(R.string.error);
                String alertMessage = error.getMessage();
                showResult(title, alertMessage);
            }
    
            @Override
            public void onSuccess(Sharer.Result result) {
                Log.d("HelloFacebook", "Success!");
                // 不为空,才分享成功
                if (result.getPostId() != null) {
                    String title = this.getActivty().getString(R.string.success);
                    String id = result.getPostId();
                    String alertMessage = this.getActivty().getString(R.string.successfully_posted_post, id);
                    showResult(title, alertMessage);
                }
            }
    
            private void showResult(String title, String alertMessage) {
                new AlertDialog.Builder(this.getActivty())
                        .setTitle(title)
                        .setMessage(alertMessage)
                        .setPositiveButton(R.string.ok, null)
                        .show();
            }
        };
    
    protected void onCreate (Bundle savedInstanceState)
    {
                 shareDialog = new ShareDialog(this. getActivty());
                 shareDialog.registerCallback( callbackManager, shareCallback);
    }
    

提交回复
热议问题