public void shareFacebook(View v) { Fragment prev = getSupportFragmentManager().findFragmentByTag("alertacompartir"); if (prev != null) { DialogFragment df = (DialogFragment) prev; df.dismiss(); } if (FacebookDialog.canPresentShareDialog( getApplicationContext(), FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this) .setLink(getResources().getString(R.string.url)) .setDescription(getResources().getString(R.string.textofacebook)) .setName(getResources().getString(R.string.app_name)) .setPicture(getResources().getString(R.string.app_imagen_url)) .build(); uiHelper.trackPendingDialogCall(shareDialog.present()); } else { Toast.makeText( getApplicationContext(), "No se puede compartir en facebook porque no tenes instalada la app de facebook", Toast.LENGTH_LONG) .show(); } }
public void shareOnFacebook(int level, long score, int obstacles) { String modo = getResources().getString(R.string.easy); if (level == 1) modo = getResources().getString(R.string.normal); else if (level == 2) modo = getResources().getString(R.string.hard); String name = "Turbo Race"; String caption = getResources().getString(R.string.caption); String picture = "http://carlospinan.com/icon/turbo_race.png"; String description = getResources().getString(R.string.fb_description); description = description.replace("{score}", score + ""); description = description.replace("{modo}", modo + ""); description = description.replace("{obstaculos}", obstacles + ""); String link = "https://play.google.com/store/apps/details?id=com.carlospinan.turborace"; if (FacebookDialog.canPresentShareDialog( getApplicationContext(), FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { // Publish the post using the Share Dialog FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this) .setLink(link) .setName(name) .setCaption(caption) .setPicture(picture) .setDescription(description) .build(); uiHelper.trackPendingDialogCall(shareDialog.present()); } else { // Fallback. For example, publish the post using the Feed Dialog publishFeedDialog(name, caption, description, link, picture); } }
@Override protected void executeImpl() { if (FacebookDialog.canPresentShareDialog( sessionManager.getActivity(), ShareDialogFeature.PHOTOS)) { FacebookDialog shareDialog = new FacebookDialog.PhotoShareDialogBuilder(sessionManager.getActivity()) .addPhotos(Utils.extractBitmaps(mPhotos)) .setPlace(mPlace) .build(); PendingCall pendingCall = shareDialog.present(); sessionManager.trackFacebookDialogPendingCall( pendingCall, new FacebookDialog.Callback() { @Override public void onError(PendingCall pendingCall, Exception error, Bundle data) { sessionManager.untrackPendingCall(); Logger.logError( PublishPhotoDialogAction.class, "Failed to share by using native dialog", error); if ("".equals(error.getMessage())) { Logger.logError( PublishPhotoDialogAction.class, "Make sure to have 'app_id' meta data value in your manifest", error); } mOnPublishListener.onFail( "Have you added com.facebook.NativeAppCallContentProvider to your manifest? " + error.getMessage()); } @Override public void onComplete(PendingCall pendingCall, Bundle data) { sessionManager.untrackPendingCall(); boolean didComplete = FacebookDialog.getNativeDialogDidComplete(data); String postId = FacebookDialog.getNativeDialogPostId(data); String completeGesture = FacebookDialog.getNativeDialogCompletionGesture(data); if (completeGesture != null) { if (completeGesture.equals("post")) { mOnPublishListener.onComplete(postId != null ? postId : "no postId return"); } else { mOnPublishListener.onFail("Canceled by user"); } } else if (didComplete) { mOnPublishListener.onComplete( postId != null ? postId : "published successfully. (post id is not availaible if you are not logged in)"); } else { mOnPublishListener.onFail("Canceled by user"); } } }); } else { mOnPublishListener.onFail("Photos sharing dialog isn't supported"); } }
private void share() { if (FacebookDialog.canPresentShareDialog( getApplicationContext(), FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { dialog.show(); // Publish the post using the Share Dialog FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this) .setLink(getLink()) .setName(getName()) .setDescription(getMessage()) .setPicture(currentView.getImageUrl()) .build(); uiHelper.trackPendingDialogCall(shareDialog.present()); } else { publishFeedDialog(); } }