当用户打开我的应用程序时,我需要在我的应用程序中共享特定部分,如果他下载我的应用程序,它会直接导航到该部分(它可能是嵌套 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);
这是我需要解决的问题
最佳答案
为了更好地分享 Facebook 中的内容,请使用最新的 Facebook SDK。这将使您的任务更简单。因为Android Intent在我们使用share to facebook的时候有自己的限制。请参阅下面关于此的我的回答
Share text via Intent on Facebook without using Facebook sdk
您发布的屏幕截图似乎有来自应用程序的共享链接。
此处介绍如何将 Facebook SDK 集成到您的项目中。
然后使用下面的代码在facebook上分享链接。
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);
可以找到来自 Facebook 的更多共享选项 here ,这非常简单明了。
编码愉快..!!
关于Android - 通过 Facebook 分享自定义链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35155890/