Search in sources :

Example 1 with MessageDialog

use of com.facebook.share.widget.MessageDialog in project react-native-fbsdk by facebook.

the class FBMessageDialogModule method canShow.

/**
 * Indicates whether it is possible to show the dialog for ShareContent of the specified type.
 * @param shareContentMap  must be a valid {@link ShareContent}.
 * @param promise Use promise to pass message dialog result to JS.
 */
@ReactMethod
public void canShow(ReadableMap shareContentMap, Promise promise) {
    if (getCurrentActivity() != null) {
        ShareContent shareContent = Utility.buildShareContent(shareContentMap);
        MessageDialog messageDialog = new MessageDialog(getCurrentActivity());
        promise.resolve(messageDialog.canShow(shareContent));
    } else {
        promise.reject("No current activity.");
    }
}
Also used : MessageDialog(com.facebook.share.widget.MessageDialog) ShareContent(com.facebook.share.model.ShareContent) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 2 with MessageDialog

use of com.facebook.share.widget.MessageDialog in project facebook-android-sdk by facebook.

the class RpsFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
        wins = savedInstanceState.getInt(WIN_KEY);
        losses = savedInstanceState.getInt(LOSS_KEY);
        ties = savedInstanceState.getInt(TIE_KEY);
        computerChoice = savedInstanceState.getInt(COMPUTER_CHOICE_KEY);
        playerChoice = savedInstanceState.getInt(PLAYER_CHOICE_KEY);
        currentState = (RpsState) savedInstanceState.getSerializable(STATE_KEY);
        result = (RpsResult) savedInstanceState.getSerializable(RESULT_KEY);
        pendingPublish = savedInstanceState.getBoolean(PENDING_PUBLISH_KEY);
        shouldImplicitlyPublish = savedInstanceState.getBoolean(IMPLICIT_PUBLISH_KEY);
    }
    callbackManager = CallbackManager.Factory.create();
    LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            AccessToken accessToken = AccessToken.getCurrentAccessToken();
            if (accessToken.getPermissions().contains(ADDITIONAL_PERMISSIONS)) {
                publishResult();
            } else {
                handleError();
            }
        }

        @Override
        public void onCancel() {
            handleError();
        }

        @Override
        public void onError(FacebookException exception) {
            handleError();
        }

        private void handleError() {
            // this means the user did not grant us write permissions, so
            // we don't do implicit publishes
            shouldImplicitlyPublish = false;
            pendingPublish = false;
        }
    });
    FacebookCallback<Sharer.Result> callback = new FacebookCallback<Sharer.Result>() {

        @Override
        public void onCancel() {
            Log.d(TAG, "Canceled");
        }

        @Override
        public void onError(FacebookException error) {
            Log.d(TAG, String.format("Error: %s", error.toString()));
        }

        @Override
        public void onSuccess(Sharer.Result result) {
            Log.d(TAG, "Success!");
        }
    };
    shareDialog = new ShareDialog(this);
    shareDialog.registerCallback(callbackManager, callback);
    messageDialog = new MessageDialog(this);
    messageDialog.registerCallback(callbackManager, callback);
    FacebookCallback<AppInviteDialog.Result> appInviteCallback = new FacebookCallback<AppInviteDialog.Result>() {

        @Override
        public void onSuccess(AppInviteDialog.Result result) {
            Log.d(TAG, "Success!");
        }

        @Override
        public void onCancel() {
            Log.d(TAG, "Canceled");
        }

        @Override
        public void onError(FacebookException error) {
            Log.d(TAG, String.format("Error: %s", error.toString()));
        }
    };
    appInviteDialog = new AppInviteDialog(this);
    appInviteDialog.registerCallback(callbackManager, appInviteCallback);
    // Initialize in-app billing service
    serviceConnection = new ServiceConnection() {

        @Override
        public void onServiceDisconnected(ComponentName name) {
            inAppBillingService = null;
            Utility.logd(TAG, "In-app billing service disconnected");
        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            inAppBillingService = IInAppBillingService.Stub.asInterface(service);
            Utility.logd(TAG, "In app billing service connected");
            try {
                Bundle ownedItems = inAppBillingService.getPurchases(IN_APP_PURCHASE_VERSION, context.getPackageName(), "inapp", null);
                int response = ownedItems.getInt("RESPONSE_CODE");
                if (response == 0) {
                    ArrayList<String> ownedSkus = ownedItems.getStringArrayList(INAPP_PURCHASE_ITEM_LIST);
                    ArrayList<String> purchaseDataList = ownedItems.getStringArrayList(INAPP_PURCHASE_DATA_LIST);
                    ArrayList<String> signatureList = ownedItems.getStringArrayList(INAPP_DATA_SIGNATURE_LIST);
                    for (int i = 0; i < purchaseDataList.size(); ++i) {
                        String purchaseData = purchaseDataList.get(i);
                        try {
                            JSONObject jo = new JSONObject(purchaseData);
                            String token = jo.getString("purchaseToken");
                            consumePurchase(context.getPackageName(), token);
                        } catch (JSONException e) {
                            Log.e(TAG, "Error parsing purchase data.", e);
                        }
                    }
                }
            } catch (RemoteException e) {
                Log.e(TAG, "Consuming purchase remote exception.", e);
            }
        }
    };
    context = this.getActivity().getApplicationContext();
    Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
    serviceIntent.setPackage("com.android.vending");
    context.bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE);
}
Also used : ServiceConnection(android.content.ServiceConnection) ShareDialog(com.facebook.share.widget.ShareDialog) Bundle(android.os.Bundle) LoginResult(com.facebook.login.LoginResult) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) LoginResult(com.facebook.login.LoginResult) IBinder(android.os.IBinder) AppInviteDialog(com.facebook.share.widget.AppInviteDialog) JSONObject(org.json.JSONObject) AccessToken(com.facebook.AccessToken) FacebookException(com.facebook.FacebookException) Sharer(com.facebook.share.Sharer) ComponentName(android.content.ComponentName) MessageDialog(com.facebook.share.widget.MessageDialog) RemoteException(android.os.RemoteException)

Example 3 with MessageDialog

use of com.facebook.share.widget.MessageDialog in project react-native-fbsdk by facebook.

the class FBMessageDialogModule method show.

/**
 * Show the provided ShareContent using the provided Activity.
 * @param shareContentMap  must be a valid {@link ShareContent}.
 * @param promise Use promise to pass message dialog result to JS.
 */
@ReactMethod
public void show(ReadableMap shareContentMap, Promise promise) {
    if (getCurrentActivity() != null) {
        ShareContent shareContent = Utility.buildShareContent(shareContentMap);
        MessageDialog messageDialog = new MessageDialog(getCurrentActivity());
        messageDialog.setShouldFailOnDataError(mShouldFailOnDataError);
        messageDialog.registerCallback(getCallbackManager(), new MessageDialogCallback(promise));
        messageDialog.show(shareContent);
    } else {
        promise.reject("No current activity.");
    }
}
Also used : MessageDialog(com.facebook.share.widget.MessageDialog) ShareContent(com.facebook.share.model.ShareContent) ReactMethod(com.facebook.react.bridge.ReactMethod)

Aggregations

MessageDialog (com.facebook.share.widget.MessageDialog)3 ReactMethod (com.facebook.react.bridge.ReactMethod)2 ShareContent (com.facebook.share.model.ShareContent)2 PendingIntent (android.app.PendingIntent)1 ComponentName (android.content.ComponentName)1 Intent (android.content.Intent)1 ServiceConnection (android.content.ServiceConnection)1 Bundle (android.os.Bundle)1 IBinder (android.os.IBinder)1 RemoteException (android.os.RemoteException)1 AccessToken (com.facebook.AccessToken)1 FacebookException (com.facebook.FacebookException)1 LoginResult (com.facebook.login.LoginResult)1 Sharer (com.facebook.share.Sharer)1 AppInviteDialog (com.facebook.share.widget.AppInviteDialog)1 ShareDialog (com.facebook.share.widget.ShareDialog)1 ArrayList (java.util.ArrayList)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1