Advertisement
Guest User

Android Share Application On Facebook

a guest
Jan 9th, 2018
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.13 KB | None | 0 0
  1.  
  2.  
  3. ********************
  4. Android Share Application On Facebook
  5. http://urlin.us/bz956
  6. (Copy & Paste link)
  7. ********************
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49. You should specify absolute url's like instead of just /yourimage.jpg. I have to share on Facebook, twitter, email and maybe other services. Can't share both */ public static void shareOnFacebook(AppCompatActivity appCompatActivity, String textBody, Uri fileUri) { Intent intent = new Intent(Intent.ACTIONSEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRATEXT,!TextUtils.isEmpty(textBody) ? textBody : ""); if (fileUri != null) { intent.putExtra(Intent.EXTRASTREAM, fileUri); intent.addFlags(Intent.FLAGGRANTREADURIPERMISSION); intent.setType("image/*"); } boolean facebookAppFound = false; List matches = appCompatActivity.getPackageManager().queryIntentActivities(intent, PackageManager.MATCHDEFAULTONLY); for (ResolveInfo info : matches) { if (info.activityInfo.packageName.toLowerCase().startsWith("com.facebook.katana") info.activityInfo.packageName.toLowerCase().startsWith("com.facebook.lite")) { intent.setPackage(info.activityInfo.packageName); facebookAppFound = true; break; } } if (facebookAppFound) { appCompatActivity.startActivity(intent); } else { showWarningDialog(appCompatActivity, appCompatActivity.getString(R.string.erroractivitynotfound)); } } public static void shareOnWhatsapp(AppCompatActivity appCompatActivity, String textBody, Uri fileUri){.} private static void showWarningDialog(Context context, String message) { new AlertDialog.Builder(context) .setMessage(message) .setNegativeButton(context.getString(R.string.close), new DialogInterface.OnClickListener() { Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }) .setCancelable(true) .create().show(); } } For getting Uri from File, use below class: public class UtilityFile { public static Nullable Uri getUriFromFile(Context context, Nullable File file) { if (file == null) return null; if (Build.VERSION.SDKINT >= Build.VERSIONCODES.N) { try { return FileProvider.getUriForFile(context, "com.my.package.fileprovider", file); } catch (Exception e) { e.printStackTrace(); return null; } } else { return Uri.fromFile(file); } } // Returns the URI path to the Bitmap displayed in specified ImageView public static Uri getLocalBitmapUri(Context context, ImageView imageView) { Drawable drawable = imageView.getDrawable(); Bitmap bmp = null; if (drawable instanceof BitmapDrawable) { bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); } else { return null; } // Store image to default external storage directory Uri bmpUri = null; try { // Use methods on Context to access package-specific directories on external storage. Stack Overflow works best with JavaScript enabled .. if i want to fill post edittext then how to work with facebook. it is not possible to use actionsend to go straight to twitter of facebook. EditRelated wikiHows How to Find and Install Free Android Apps How to Install the wikiHow Android App How to Use Bump Between an iPhone and Android How to Copy and Paste on Facebook How to Retrieve Deleted Facebook Messages How to Download Facebook Videos For Free How to Make a Slideshow on Facebook How to Make a Heart on Facebook How to Post a YouTube Video on Facebook How to Successfully Access Facebook in China Article Info Categories: Facebook Discuss Print Edit Send fan mail to authors Thanks to all authors for creating a page that has been read 13,916 times. Not the answer you're looking for? Browse other questions tagged android facebook android-intent or ask your own question. Also, the images on the page must be publicly accessible to the Facebook crawler. If you are logged in, it will open the share dialog and put in the "Share url" from the Intent Extra. You can do this through controls on your Android. content . All the info you need is in www.facebook.com/share/ . edited my answer :) –Ovidiu Latcu Jun 1 '12 at 12:14 However, in Android is more common to put a global Share button rather than only FB and Twitter ones. This is what confuses me though, the first snippet of code you posted works fine for posting to every other app with share intents available, however with Facebook's intent it takes the user to a blank "Write something" facebook page as if it's not sending (or possibly receiving) the text within the EXTRATEXT field. Home About wikiHow Jobs Terms of Use RSS Site map Log In Mobile view All text shared under a Creative Commons License. SDKsiOS SDKAndroid SDKJavaScript SDKPHP SDKUnity SDK. Let me introduce myself more formally, Im a normal guy, engineer by education who is passionate about Programming and Internet. Email Sign Up or sign in with Google Facebook Android and Facebook share intent Ask Question up vote 73 down vote favorite 38 I'm developing an Android app and am interested to know how you can update the app user's status from within the app using Android's share intents. How does Facebook Sharer select Images and other metadata when sharing my URL? How do I tell Facebook which image to use when my page gets shared? Facebook has a set of open-graph meta tags that it looks at to decide which image to show. The user will then be presented with an image selector dialog: I specified the appropriate image meta tags. If you use other solution instead of below code, don't forget to specify package name com.facebook.lite as well, which is package name of Facebook Lite. Create an Intent object with appropriate info and then check if the Intent is callable or not using the following function: private boolean isCallable ( Intent intent ) { List ResolveInfo > list = getPackageManager (). If there is and you are not logged in, it goes to the login screen. Stack Overflow Questions Developer Jobs Tags Users current community help chat Stack Overflow Meta Stack Overflow your communities Sign up or log in to customize your list. Stack Overflow Questions Developer Jobs Tags Users current community help chat Stack Overflow Meta Stack Overflow your communities Sign up or log in to customize your list. Style the A tag in any way you want to. Used to work. That seems to be making the difference. (Most of the other solutions in this question bring up a huge "Complete action using" dialog which isn't optimal at all!) String urlToShare = " Intent intent = new Intent(Intent.ACTIONSEND); intent.setType("text/plain"); // intent.putExtra(Intent.EXTRASUBJECT, "Foo bar"); // NB: has no effect! intent.putExtra(Intent.EXTRATEXT, urlToShare); // See if official Facebook app is found boolean facebookAppFound = false; List matches = getPackageManager().queryIntentActivities(intent, 0); for (ResolveInfo info : matches) { if (info.activityInfo.packageName.toLowerCase().startsWith("com.facebook.katana")) { intent.setPackage(info.activityInfo.packageName); facebookAppFound = true; break; } } // As fallback, launch sharer.php in a browser if (!facebookAppFound) { String sharerUrl = " + urlToShare; intent = new Intent(Intent.ACTIONVIEW, Uri.parse(sharerUrl)); } startActivity(intent); (Regarding the com.facebook.katana package name, see MatheusJardimB's comment.) The result looks like this on my Nexus 7 (Android 4.4) with Facebook app installed: shareimprove this answer edited May 23 '17 at 12:18 Communityf 11 answered Jan 17 '14 at 15:02 Jonik 45.9k51197298 2 "com.facebook.katana" is the package name for Facebook app and "com.facebook.orca" is for FB Messenger app. It's back! Take the 2018 Developer Survey today . Stack Overflow works best with JavaScript enabled .. public void invokeShare(Activity activity, String quote, String credit) { Intent shareIntent = new Intent(android.content.Intent.ACTIONSEND); shareIntent.setType("text/plain"); shareIntent.putExtra(android.content.Intent.EXTRASUBJECT, activity.getString(R.string.sharesubject)); shareIntent.putExtra(android.content.Intent.EXTRATEXT, "Example text"); activity.startActivity(Intent.createChooser(shareIntent, activity.getString(R.string.sharetitle))); } UPDATE: Having done more digging, it looks as though it's a bug with Facebook's app that has yet to be resolved! (facebook bug) For the mean time it looks like I'm just going to have to put up with the negative "Sharing doesn't work!!!" reviews 5a02188284
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement