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.");
}
}
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);
}
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.");
}
}
Aggregations