Min*_*wzy 2 android share facebook android-intent
当用户打开它时,我需要在我的应用程序中共享特定部分,如果他下载我的应用程序,它直接导航到此部分(它可能是嵌套片段).
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);
Run Code Online (Sandbox Code Playgroud)
这是我需要接近的
为了在Facebook上分享一些东西,最好使用最新的Facebook SDK.它将使您的任务更简单.因为当我们使用分享到Facebook时,Android Intent有自己的限制.请参阅下面的答案
在Facebook上通过Intent分享文本而不使用Facebook sdk
您发布的屏幕截图似乎是从应用程序共享链接.
以下是将SDK 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);
Run Code Online (Sandbox Code Playgroud)
这里可以找到更多来自Facebook的共享选项,这非常简单明了.
快乐的编码.. !!
| 归档时间: |
|
| 查看次数: |
7890 次 |
| 最近记录: |