Java Question onActivityResult Question

DevBaby

Active Member
Licensed User
Longtime User
I have the following code to launch the facebook share dialog box, once the user shares their post, the OnActiivityResult should be raised which then calls the Callbackmanager that handles the result (methods onsuccess etc.)

I have read the tutorial here, but I don't understand the "data flow" and when the startactivityforresult should be called (before or after showing the dialog box?), nor do I understand what the result is (a code, data etc) to be able to use it.

the code is below,

B4X:
package cm.fb.share2;

import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;

import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.share.Sharer;
import com.facebook.share.model.ShareLinkContent;
import com.facebook.share.widget.ShareDialog;



@ActivityObject
@DependsOn(values={"Facebooksdk400"})
@Permissions(values={"android.permission.INTERNET"})
@ShortName("fbcommand")


public class fbcommand  {

    CallbackManager callbackManager;
    ShareDialog shareDialog;
      
    public void FbConnectTest(final BA ba, String Title, String Msg, String LinkUrl, String ImageUrl) {
  
        FacebookSdk.sdkInitialize(BA.applicationContext);
        CallbackManager callbackManager = CallbackManager.Factory.create();
  
              
        ShareDialog shareDialog = new ShareDialog(ba.activity);
      
        shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
      
            @Override
            public void onSuccess(Sharer.Result result) {
              
                Log.d("B4A", "Facebook Message sent");
              
            }  
          
            @Override
            public void onCancel() {
            }

            @Override
            public void onError(FacebookException e) {
            }
        });
      
        Log.d("B4A", "CallbackManger Registered");
      
        if (ShareDialog.canShow(ShareLinkContent.class)) {
            ShareLinkContent linkContent = new ShareLinkContent.Builder()
                    .setContentTitle(Title)
                    .setContentDescription(Msg)
                    .setImageUrl(Uri.parse(ImageUrl))
                    .setContentUrl(Uri.parse(LinkUrl))
                    .build();
                  
            shareDialog.show(linkContent);
        }
  
    }  
      
  
    protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
        callbackManager.onActivityResult(requestCode, resultCode, data);      
    }
}
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
i guess before as the ion will call facebook (in your example)
 
Top