Android - add custom link via facebook

I need to separate a certain part in my application, when the user opens it, if he downloads my application, it will go directly to this part (this may be a nested fragment).

String AppURL = "https://play.google.com/store/apps/details?id=" + getApplicationContext().getPackageName(); String urlToShare = "http://stackoverflow.com/questions/7545254"; // I need custom url to specific part in my app // See if official Facebook app is found boolean facebookAppFound = false; List<ResolveInfo> 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 = "https://www.facebook.com/sharer/sharer.php?u=" + urlToShare; intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl)); }else{ Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); // intent.putExtra(Intent.EXTRA_SUBJECT, "Foo bar"); // NB: has no effect! intent.putExtra(Intent.EXTRA_TEXT, urlToShare); } startActivity(intent); 

that's what i need to get closer to

enter image description here

+2
android android-intent facebook share
source share
2 answers

To share something on Facebook, better go with the latest Facebook SDK. This will simplify your task. Because Android Intent has its limitations when we use share to facebook. See my answer below regarding this.

Share text via Intent on Facebook without using Facebook sdk

The screenshot you posted seems to contain a link from within the app.

Here's how you integrate the Facebook SDK into your project.

Facebook SDK integration

Then use the following code to share your facebook link.

 ShareDialog shareDialog; FacebookSdk.sdkInitialize(Activity.this); shareDialog = new ShareDialog(act); ShareLinkContent linkContent = new ShareLinkContent.Builder() .setContentTitle("title") .setContentDescription( "Description") .setContentUrl(Uri.parse("your url")).build(); shareDialog.show(linkContent); 

More detailed sharing options from Facebook can be found here , which is quite simple and simple.

Happy coding .. !!

+7
source share

Try the following code:

 File mFileImagePath = " /storage/emulated/0/Image Editor/Media/FilterImages/Image_Editor_1547816365839.jpg "; // Just example you use file URL private void shareFacebook(File mFileImagePath) { String application = "com.facebook.katana"; boolean installed = checkAppInstall(application); if (installed) { Intent mIntentShare = new Intent(Intent.ACTION_SEND); String mStrExtension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(mFileImagePath).toString()); String mStrMimeType = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(mStrExtension); if (mStrExtension.equalsIgnoreCase("") || mStrMimeType == null) { // if there is no extension or there is no definite mimetype, still try to open the file mIntentShare.setType("text*//*"); } else { mIntentShare.setType(mStrMimeType); } mIntentShare.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(mFileImagePath)); mIntentShare.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); mIntentShare.setPackage(application); startActivity(mIntentShare); } else { Toast.makeText(mContext, "Facebook have not been installed.", Toast.LENGTH_SHORT).show(); } } private boolean checkAppInstall(String uri) { PackageManager pm = getPackageManager(); try { pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES); return true; } catch (PackageManager.NameNotFoundException e) { //Error } return false; } 

This code works for me and will work on all Android devices.

0
source share

All Articles