Search in sources :

Example 1 with AppInviteContent

use of com.facebook.share.model.AppInviteContent in project react-native-fbsdk by facebook.

the class FBAppInviteDialogModule method show.

/**
     * Helper to show the provided {@link com.facebook.share.model.AppInviteContent}.
     * @param appInviteContentMap must be a valid {@link AppInviteContent}
     * @param promise Use promise to pass the app invite dialog result to JS.
     */
@ReactMethod
public void show(ReadableMap appInviteContentMap, Promise promise) {
    if (getCurrentActivity() != null) {
        AppInviteDialog appInviteDialog = new AppInviteDialog(getCurrentActivity());
        AppInviteContent appInviteContent = Utility.buildAppInviteContent(appInviteContentMap);
        appInviteDialog.registerCallback(getCallbackManager(), new AppInviteDialogCallback(promise));
        appInviteDialog.show(appInviteContent);
    } else {
        promise.reject("No current activity.");
    }
}
Also used : AppInviteDialog(com.facebook.share.widget.AppInviteDialog) AppInviteContent(com.facebook.share.model.AppInviteContent) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 2 with AppInviteContent

use of com.facebook.share.model.AppInviteContent in project CodenameOne by codenameone.

the class FacebookImpl method inviteFriends.

@Override
public void inviteFriends(String appLinkUrl, String previewImageUrl, final Callback cb) {
    if (AndroidNativeUtil.getActivity() == null) {
        throw new RuntimeException("Cannot invite friends while running in the background.");
    }
    if (AppInviteDialog.canShow()) {
        AppInviteContent content = new AppInviteContent.Builder().setApplinkUrl(appLinkUrl).setPreviewImageUrl(previewImageUrl).build();
        final CodenameOneActivity activity = (CodenameOneActivity) AndroidNativeUtil.getActivity();
        if (cb == null) {
            AppInviteDialog.show(activity, content);
        } else {
            AppInviteDialog appInviteDialog = new AppInviteDialog(activity);
            final CallbackManager mCallbackManager = CallbackManager.Factory.create();
            activity.setIntentResultListener(new IntentResultListener() {

                @Override
                public void onActivityResult(int requestCode, int resultCode, Intent data) {
                    mCallbackManager.onActivityResult(requestCode, resultCode, data);
                    activity.restoreIntentResultListener();
                }
            });
            appInviteDialog.registerCallback(mCallbackManager, new FacebookCallback<AppInviteDialog.Result>() {

                @Override
                public void onSuccess(AppInviteDialog.Result result) {
                    Display.getInstance().callSerially(new Runnable() {

                        @Override
                        public void run() {
                            cb.onSucess(null);
                        }
                    });
                }

                @Override
                public void onCancel() {
                    Display.getInstance().callSerially(new Runnable() {

                        @Override
                        public void run() {
                            cb.onError(null, null, -1, "User Cancelled");
                        }
                    });
                }

                @Override
                public void onError(final FacebookException e) {
                    Display.getInstance().callSerially(new Runnable() {

                        @Override
                        public void run() {
                            cb.onError(null, e, 0, e.getMessage());
                        }
                    });
                }
            });
            appInviteDialog.show(content);
        }
    }
}
Also used : CodenameOneActivity(com.codename1.impl.android.CodenameOneActivity) Intent(android.content.Intent) CallbackManager(com.facebook.CallbackManager) AppInviteDialog(com.facebook.share.widget.AppInviteDialog) IntentResultListener(com.codename1.impl.android.IntentResultListener) FacebookException(com.facebook.FacebookException) AppInviteContent(com.facebook.share.model.AppInviteContent)

Aggregations

AppInviteContent (com.facebook.share.model.AppInviteContent)2 AppInviteDialog (com.facebook.share.widget.AppInviteDialog)2 Intent (android.content.Intent)1 CodenameOneActivity (com.codename1.impl.android.CodenameOneActivity)1 IntentResultListener (com.codename1.impl.android.IntentResultListener)1 CallbackManager (com.facebook.CallbackManager)1 FacebookException (com.facebook.FacebookException)1 ReactMethod (com.facebook.react.bridge.ReactMethod)1