public void ShareTextFb() { shareDialog = new ShareDialog(this); ShareLinkContent content = new ShareLinkContent.Builder() .setContentTitle(editTitle.getText().toString()) .setContentDescription(editDesc.getText().toString()) .setContentUrl(Uri.parse(editUrl.getText().toString())) .build(); shareDialog.registerCallback( callbackManager, new FacebookCallback<Sharer.Result>() { @Override public void onSuccess(Sharer.Result result) { info.setText("sukses"); } @Override public void onCancel() { info.setText("cancel"); } @Override public void onError(FacebookException error) { info.setText("error" + error.getMessage().toString()); } }); shareDialog.show(content); }
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_favorite) { Log.d(DEBUG_TAG, "Favorite toggled"); if (FavoritesManager.isFavorite(ResultActivity.this, ResultActivity.symbol)) { FavoritesManager.removeFavorite(ResultActivity.this, ResultActivity.symbol); } else { FavoritesManager.addFavorite(ResultActivity.this, ResultActivity.symbol); // Toast at 1:23 Toast.makeText( ResultActivity.this, "Bookmarked " + ResultActivity.name + "!!", Toast.LENGTH_SHORT) .show(); } setFavoriteIcon(); return true; } else if (id == R.id.action_facebook) { Log.d(DEBUG_TAG, "Facebook share button clicked"); // Toast at 1:27 Toast.makeText( ResultActivity.this, "Sharing " + ResultActivity.name + "!!", Toast.LENGTH_SHORT) .show(); shareDialog = new ShareDialog(this); shareDialog.registerCallback(callbackManager, shareCallback); if (ShareDialog.canShow(ShareLinkContent.class)) { ShareLinkContent linkContent = new ShareLinkContent.Builder() .setContentTitle( "Current Stock Price of " + ResultActivity.name + " is $" + ResultActivity.lastPrice) .setContentDescription( "Stock Information of " + ResultActivity.name + " (" + ResultActivity.symbol + ")") .setImageUrl( Uri.parse( "https://chart.yahoo.com/t?s=" + ResultActivity.symbol + "&lang=en-US&width=400&height=300")) .setContentUrl(Uri.parse("https://finance.yahoo.com/q?s=" + symbol)) .build(); shareDialog.setShouldFailOnDataError(true); shareDialog.show(linkContent, ShareDialog.Mode.FEED); } return true; } return super.onOptionsItemSelected(item); }
@OnClick(R.id.btn_share) public void facebookShare() { if (ShareDialog.canShow(ShareLinkContent.class)) { ShareLinkContent content = new ShareLinkContent.Builder() .setContentUrl(Uri.parse("http://collide.com")) .setContentDescription(getIntent().getStringExtra("note")) .setContentTitle("I unlocked the song " + getIntent().getStringExtra("title")) .setImageUrl(Uri.parse(getIntent().getStringExtra("image_link"))) .build(); shareDialog.show(this, content); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mCallbackManager = CallbackManager.Factory.create(); LoginManager.getInstance() .registerCallback( mCallbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { handlePedingAcction(); } @Override public void onCancel() {} @Override public void onError(FacebookException error) { Log.d("PostToSocialActivity", error.getMessage()); } }); mShareDialog = new ShareDialog(this); mShareDialog.registerCallback(mCallbackManager, shareCallback); mProfileTracker = new ProfileTracker() { @Override protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) { handlePedingAcction(); } }; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mCallbackManager = CallbackManager.Factory.create(); shareDialog = new ShareDialog(this); shareDialog.registerCallback(mCallbackManager, mCallback); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_capture); CalligraphyConfig.initDefault( new CalligraphyConfig.Builder() .setDefaultFontPath("fonts/Roboto-RobotoRegular.ttf") .setFontAttrId(R.attr.fontPath) .build()); ButterKnife.bind(this); setSupportActionBar(toolbar); getSupportActionBar().setDisplayShowTitleEnabled(false); getSupportActionBar().setDisplayHomeAsUpEnabled(true); toolbar.setNavigationIcon(R.drawable.icn_back); title.setText("COLLECTIONS"); FacebookSdk.sdkInitialize(this); callbackManager = CallbackManager.Factory.create(); shareDialog = new ShareDialog(this); // this part is optional shareDialog.registerCallback( callbackManager, new FacebookCallback<Sharer.Result>() { @Override public void onSuccess(Sharer.Result result) { if (result.getPostId() != null) { Toast.makeText(getBaseContext(), "Success", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getBaseContext(), "Problem posting story", Toast.LENGTH_SHORT).show(); } } @Override public void onCancel() { Toast.makeText(getBaseContext(), "Cancelled", Toast.LENGTH_SHORT).show(); } @Override public void onError(FacebookException e) { Toast.makeText(getBaseContext(), "Error sharing", Toast.LENGTH_SHORT).show(); } }); song_name.setText(getIntent().getStringExtra("title").toUpperCase()); Picasso.with(getBaseContext()) .load(getIntent().getStringExtra("image_link")) .placeholder(R.drawable.speaker_icn1) .into(album_art); note.setText(getIntent().getStringExtra("note")); playlist.setText(Html.fromHtml("or <u>Add to Playlist</u>")); }
public static void shareFeed(String title, String desc, String caption, String pictureUrl) { ShareLinkContent.Builder builder = new ShareLinkContent.Builder(); if (title != null) builder.setContentTitle(title); if (desc != null) builder.setContentDescription(desc); // NOTE: for android, caption is the URL of the HTML5 game's page OR the app store link, TBD by // developer // e.g. "http://funfe.com" if (caption != null) builder.setContentUrl(Uri.parse(caption)); // e.g. "https://developers.facebook.com" if (pictureUrl != null) builder.setImageUrl(Uri.parse(pictureUrl)); ShareLinkContent content = builder.build(); KoreActivity activity = KoreActivity.getInstance(); ShareDialog dialog = new ShareDialog(activity); // CallbackManager cbManager = CallbackManager.Factory.create(); // dialog.registerCallback(cbManager, new FacebookCallback<Sharer.Result>() { // @Override // public void onSuccess(Sharer.Result result) { // Log.d("WynLog", "WynFBKore CB onSuccess : " + result.toString()); // } // @Override // public void onCancel() { // Log.d("WynLog", "WynFBKore CB onCancel"); // } // @Override // public void onError(FacebookException error) { // Log.d("WynLog", "WynFBKore CB onError : " + error.toString()); // } // }); dialog.show(content); Log.d( "WynLog", "WynFBKore shareFeed : " + title + " , " + desc + " , " + caption + " , " + pictureUrl); }
private void shareOnFB() { // Create an object Set<String> permissions = AccessToken.getCurrentAccessToken().getPermissions(); if (!permissions.contains("publish_actions")) { LoginManager.getInstance() .registerCallback( callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { if (AccessToken.getCurrentAccessToken() .getPermissions() .contains("publish_actions")) { shareOnFB(); } } @Override public void onCancel() {} @Override public void onError(FacebookException e) {} }); LoginManager.getInstance() .logInWithPublishPermissions(PaymentActivity.this, Arrays.asList("publish_actions")); } else { String dateString = ""; String dateString2 = ""; try { Date date = new Date(mEventData.getSchedule().getStart_date()); SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.ENGLISH); dateString = sdf2.format(date); date.setTime(mEventData.getSchedule().getEnd_date()); dateString2 = sdf2.format(date); } catch (Exception e) { e.printStackTrace(); Crashlytics.logException(e); } String url = "http://purplesq.com/event/" + mEventData.get_id(); ShareOpenGraphObject eventObject = new ShareOpenGraphObject.Builder() .putString("fb:app_id", "852292264845107") .putString("og:type", "purplesquirrel:event") .putString("og:title", mEventData.getName()) .putString("og:description", mEventData.getSummary()) .putString("og:url", url) .putString("og:image", mEventData.getThumbnail()) .build(); ShareOpenGraphAction action = new ShareOpenGraphAction.Builder() .setActionType("purplesquirrel:attend") .putString("start_time", dateString) .putString("expires_time", dateString2) .putObject("event", eventObject) .build(); ShareOpenGraphContent content = new ShareOpenGraphContent.Builder() .setPreviewPropertyName("event") .setAction(action) .build(); if (ShareDialog.canShow(ShareOpenGraphContent.class)) { ShareDialog shareDialog = new ShareDialog(this); shareDialog.registerCallback( callbackManager, new FacebookCallback<Result>() { @Override public void onSuccess(Result result) { if (!TextUtils.isEmpty(result.getPostId())) { if (Config.DEBUG) { Log.i("Nish", "FB Share Success : " + result.getPostId()); } findViewById(R.id.activity_payment_coupon_cardview).setVisibility(View.GONE); } else { if (Config.DEBUG) { Log.i("Nish", "FB Share Success without postId "); } } } @Override public void onCancel() {} @Override public void onError(FacebookException e) {} }); shareDialog.show(content); } } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); initFacebook(); setContentView(R.layout.activity_main); sp = this.getSharedPreferences("Accounts", Context.MODE_PRIVATE); tv_name = (TextView) findViewById(R.id.tv_name); profilePictureView = (ProfilePictureView) findViewById(R.id.proflie_picture); profilePictureView.setCropped(true); profilePictureView.setPresetSize(ProfilePictureView.NORMAL); // setting profile from storage; String id = sp.getString("fb_id", ""); String name = sp.getString("fb_name", ""); profilePictureView.setProfileId(id); tv_name.setText(name); fbLoginButton = (LoginButton) findViewById(R.id.fb_login_button); fbShareButton = (ShareButton) findViewById(R.id.fb_share_button); if (id != "") { fbShareButton.setEnabled(true); } fbShareButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (ShareDialog.canShow(ShareLinkContent.class)) { ShareLinkContent linkContent = new ShareLinkContent.Builder() .setContentTitle("I am the king") .setContentDescription("No doubt") .setImageUrl( Uri.parse( "http://vignette2.wikia.nocookie.net/genealogy/images/2/28/King_Henry_I_from_NPG.jpg/revision/latest?cb=20090610170605")) .setContentUrl(Uri.parse("http://stackoverflow.com/")) .build(); // Mode.FEED:Shared link with this account // Mode.NATIVE:Shared link with the account that you have logged in the facebook app // So, if your app ask for login, you use Mode.FEED to share link // In general, you use Mode.AUTOMATIC shareDialog.show(linkContent, ShareDialog.Mode.FEED); } } }); shareDialog.registerCallback( callbackManager, new FacebookCallback<Sharer.Result>() { @Override public void onSuccess(Sharer.Result result) { Log.d(TAG, "success"); } @Override public void onError(FacebookException error) { Log.d(TAG, "error"); } @Override public void onCancel() { Log.d(TAG, "cancel"); } }); fbLoginButton.registerCallback( callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { String id = loginResult.getAccessToken().getUserId(); profilePictureView.setProfileId(id); fbShareButton.setEnabled(true); SharedPreferences.Editor editor = sp.edit(); editor.putString("fb_id", id); editor.commit(); getMoreInformation(loginResult); Log.d(TAG, "Facebook Login Successful!"); Log.d(TAG, "Logged in user Details : "); Log.d(TAG, "--------------------------"); Log.d(TAG, "User ID : " + id); Log.d(TAG, "Authentication Token : " + loginResult.getAccessToken().getToken()); Toast.makeText(MainActivity.this, "Login Successful!", Toast.LENGTH_LONG).show(); } @Override public void onCancel() { Toast.makeText(MainActivity.this, "Login cancelled by user!", Toast.LENGTH_LONG).show(); Log.d(TAG, "Facebook Login failed!!"); } @Override public void onError(FacebookException e) { Toast.makeText(MainActivity.this, "Login unsuccessful!", Toast.LENGTH_LONG).show(); Log.d(TAG, "Facebook Login failed!!"); } }); fbLoginButton.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // Log.d(TAG, "beforeTextChanged"); } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // Log.d(TAG, "onTextChanged"); } @Override public void afterTextChanged(Editable s) { // Log.d(TAG, "afterTextChanged"); if (AccessToken.getCurrentAccessToken() == null) { clearFbData(); } } }); }
@Override protected void pluginInitialize() { FacebookSdk.sdkInitialize(cordova.getActivity().getApplicationContext()); // create callbackManager callbackManager = CallbackManager.Factory.create(); // create AppEventsLogger logger = AppEventsLogger.newLogger(cordova.getActivity().getApplicationContext()); // Set up the activity result callback to this class cordova.setActivityResultCallback(this); LoginManager.getInstance() .registerCallback( callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(final LoginResult loginResult) { GraphRequest.newMeRequest( loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted(JSONObject jsonObject, GraphResponse response) { if (response.getError() != null) { if (graphContext != null) { graphContext.error( getFacebookRequestErrorResponse(response.getError())); } else if (loginContext != null) { loginContext.error( getFacebookRequestErrorResponse(response.getError())); } return; } // If this login comes after doing a new permission request // make the outstanding graph call if (graphContext != null) { makeGraphCall(); return; } Log.d(TAG, "returning login object " + jsonObject.toString()); loginContext.success(getResponse()); loginContext = null; } }) .executeAsync(); } @Override public void onCancel() { FacebookOperationCanceledException e = new FacebookOperationCanceledException(); handleError(e, loginContext); } @Override public void onError(FacebookException e) { Log.e("Activity", String.format("Error: %s", e.toString())); handleError(e, loginContext); } }); shareDialog = new ShareDialog(cordova.getActivity()); shareDialog.registerCallback( callbackManager, new FacebookCallback<Sharer.Result>() { @Override public void onSuccess(Sharer.Result result) { if (showDialogContext != null) { showDialogContext.success(result.getPostId()); showDialogContext = null; } } @Override public void onCancel() { FacebookOperationCanceledException e = new FacebookOperationCanceledException(); handleError(e, showDialogContext); } @Override public void onError(FacebookException e) { Log.e("Activity", String.format("Error: %s", e.toString())); handleError(e, showDialogContext); } }); messageDialog = new MessageDialog(cordova.getActivity()); messageDialog.registerCallback( callbackManager, new FacebookCallback<Sharer.Result>() { @Override public void onSuccess(Sharer.Result result) { if (showDialogContext != null) { showDialogContext.success(); showDialogContext = null; } } @Override public void onCancel() { FacebookOperationCanceledException e = new FacebookOperationCanceledException(); handleError(e, showDialogContext); } @Override public void onError(FacebookException e) { Log.e("Activity", String.format("Error: %s", e.toString())); handleError(e, showDialogContext); } }); gameRequestDialog = new GameRequestDialog(cordova.getActivity()); gameRequestDialog.registerCallback( callbackManager, new FacebookCallback<GameRequestDialog.Result>() { @Override public void onSuccess(GameRequestDialog.Result result) { if (showDialogContext != null) { try { JSONObject json = new JSONObject(); json.put("requestId", result.getRequestId()); json.put("recipientsIds", new JSONArray(result.getRequestRecipients())); showDialogContext.success(); showDialogContext = null; } catch (JSONException ex) { showDialogContext.success(); showDialogContext = null; } } } @Override public void onCancel() { FacebookOperationCanceledException e = new FacebookOperationCanceledException(); handleError(e, showDialogContext); } @Override public void onError(FacebookException e) { Log.e("Activity", String.format("Error: %s", e.toString())); handleError(e, showDialogContext); } }); appInviteDialog = new AppInviteDialog(cordova.getActivity()); appInviteDialog.registerCallback( callbackManager, new FacebookCallback<AppInviteDialog.Result>() { @Override public void onSuccess(AppInviteDialog.Result result) { if (showDialogContext != null) { showDialogContext.success(); showDialogContext = null; } } @Override public void onCancel() { FacebookOperationCanceledException e = new FacebookOperationCanceledException(); handleError(e, showDialogContext); } @Override public void onError(FacebookException e) { Log.e("Activity", String.format("Error: %s", e.toString())); handleError(e, showDialogContext); } }); }
private void executeDialog(JSONArray args, CallbackContext callbackContext) { Map<String, String> params = new HashMap<String, String>(); String method = null; JSONObject parameters; try { parameters = args.getJSONObject(0); } catch (JSONException e) { parameters = new JSONObject(); } Iterator<String> iter = parameters.keys(); while (iter.hasNext()) { String key = iter.next(); if (key.equals("method")) { try { method = parameters.getString(key); } catch (JSONException e) { Log.w(TAG, "Nonstring method parameter provided to dialog"); } } else { try { params.put(key, parameters.getString(key)); } catch (JSONException e) { // Need to handle JSON parameters Log.w(TAG, "Non-string parameter provided to dialog discarded"); } } } if (method == null) { callbackContext.error("No method provided"); } else if (method.equalsIgnoreCase("apprequests")) { if (!GameRequestDialog.canShow()) { callbackContext.error("Cannot show dialog"); return; } showDialogContext = callbackContext; PluginResult pr = new PluginResult(PluginResult.Status.NO_RESULT); pr.setKeepCallback(true); showDialogContext.sendPluginResult(pr); GameRequestContent.Builder builder = new GameRequestContent.Builder(); if (params.containsKey("message")) builder.setMessage(params.get("message")); if (params.containsKey("to")) builder.setTo(params.get("to")); if (params.containsKey("data")) builder.setData(params.get("data")); if (params.containsKey("title")) builder.setTitle(params.get("title")); if (params.containsKey("objectId")) builder.setObjectId(params.get("objectId")); if (params.containsKey("actionType")) { try { final GameRequestContent.ActionType actionType = GameRequestContent.ActionType.valueOf(params.get("actionType")); builder.setActionType(actionType); } catch (IllegalArgumentException e) { Log.w(TAG, "Discarding invalid argument actionType"); } } if (params.containsKey("filters")) { try { final GameRequestContent.Filters filters = GameRequestContent.Filters.valueOf(params.get("filters")); builder.setFilters(filters); } catch (IllegalArgumentException e) { Log.w(TAG, "Discarding invalid argument filters"); } } gameRequestDialog.show(builder.build()); } else if (method.equalsIgnoreCase("share")) { if (!ShareDialog.canShow(ShareLinkContent.class)) { callbackContext.error("Cannot show dialog"); return; } showDialogContext = callbackContext; PluginResult pr = new PluginResult(PluginResult.Status.NO_RESULT); pr.setKeepCallback(true); showDialogContext.sendPluginResult(pr); ShareLinkContent content = buildContent(params); shareDialog.show(content); } else if (method.equalsIgnoreCase("feed")) { ShareLinkContent content = buildContent(params); ShareApi.share(content, null); callbackContext.success(); } else if (method.equalsIgnoreCase("share_open_graph")) { if (!ShareDialog.canShow(ShareOpenGraphContent.class)) { callbackContext.error("Cannot show dialog"); return; } showDialogContext = callbackContext; PluginResult pr = new PluginResult(PluginResult.Status.NO_RESULT); pr.setKeepCallback(true); showDialogContext.sendPluginResult(pr); if (!params.containsKey("action")) { callbackContext.error("Missing required parameter \"action\""); } ShareOpenGraphAction openGraphAction = new ShareOpenGraphAction.Builder().setActionType(params.get("action")).build(); ShareOpenGraphContent.Builder content = new ShareOpenGraphContent.Builder().setAction(openGraphAction); if (params.containsKey("previewPropertyName")) content.setPreviewPropertyName(params.get("previewPropertyName")); shareDialog.show(content.build()); } else if (method.equalsIgnoreCase("send")) { if (!MessageDialog.canShow(ShareLinkContent.class)) { callbackContext.error("Cannot show dialog"); return; } showDialogContext = callbackContext; PluginResult pr = new PluginResult(PluginResult.Status.NO_RESULT); pr.setKeepCallback(true); showDialogContext.sendPluginResult(pr); ShareLinkContent.Builder builder = new ShareLinkContent.Builder(); if (params.containsKey("link")) builder.setContentUrl(Uri.parse(params.get("link"))); if (params.containsKey("caption")) builder.setContentTitle(params.get("caption")); if (params.containsKey("picture")) builder.setImageUrl(Uri.parse(params.get("picture"))); if (params.containsKey("description")) builder.setContentDescription(params.get("description")); messageDialog.show(builder.build()); } else { callbackContext.error("Unsupported dialog method."); } }