Android - 通过Facebook分享自定义链接 [英] Android - Share custom link via facebook

查看:304
本文介绍了Android - 通过Facebook分享自定义链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果他下载我的应用程序直接导航到这个部分(可能是嵌套的片段),我需要在用户打开应用程序时分享我的应用程序的具体部分。

I need to share specific part in my app when user open it , if he download my app it navigate direct to this part (it may be 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);

这里是我需要做的

推荐答案

为了在Facebook中分享更多的东西, Facebook SDK。这将使您的任务更简单。因为Android Intent在我们使用share到Facebook时有自己的限制。请参阅我的答案下面这个

In order to share the something in Facebook better go with latest Facebook SDK. It will make your task simpler. Because Android Intent has its own restrictions when we use share to facebook. Refer my answer below regarding this

通过意图在Facebook上分享文本而不使用Facebook sdk

您发布的屏幕截图似乎有从应用程序共享链接。

The screenshot that you posted seems to have the sharing of link from the App.

这里是如何将Facebook SDK整合到您的项目中。

Here is how you will integrate the Facebook SDK to your project.

Facebook SDK集成

然后使用以下代码在Facebook上分享链接。

Then use the following code to share link on the 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找到更多的共享选项这里,这很简单直接。

More sharing options from Facebook can be found here, which is pretty simple and straightforward.

快乐编码.. !!

这篇关于Android - 通过Facebook分享自定义链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆