【Android】Share via facebook with appName or without appName 有标签、无标签
来源:互联网 发布:mac pro 怎么弹出u盘 编辑:程序博客网 时间:2024/05/17 02:26
转载署源–By-KyleCe
————————————
1. 通过 Action_View
private void shareFBViaActionView(Context context) { String urlToShare = "https://www.numetriclabz.com/android-linkedin-integration-login-tutorial/"; Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, urlToShare);// See if official Facebook app is found boolean facebookAppFound = false; List<ResolveInfo> matches = context.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)); } context.startActivity(intent); }
如果已经安装facebook native应用,则会直接跳到facebook的分享界面,可以看到富文本框里的内容是不带AppName的:(图中最底部的一行)
2.如果分享出来的链接不遵循web的相应标准
facebook是抓取不到具体的标题、副标题、图片信息的,这种情况下,如果想设置这些信息,可以通过下面的方法尝试:(当然,你需要在app中加入facebook sdk,在manifest中加入相应Activity声明,这些在官网文档中都有说明,不赘述)
ShareDialog shareDialog = new ShareDialog(activityForResult); // initialize facebook shareDialog.if (ShareDialog.canShow(ShareLinkContent.class)) { String title = "Tips"; String description = "How to fix problem?"; String contentUrl = "http://pin.it/TLl3GcY"; ShareLinkContent linkContent = new ShareLinkContent.Builder() .setContentTitle(title) .setImageUrl(Uri.parse("https://www.numetriclabz.com/wp-content/uploads/2015/11/114.png")) .setContentDescription(description) .setContentUrl(Uri.parse(contentUrl)) .build(); shareDialog.show(linkContent); // Show facebook ShareDialog }
值得注意的是,用这种dialog形式的分享框,在手机上已经安装facebook native 应用的情况下,是会直接跳转到facebook的,并且会带上你在申请appId时所填的appName;
如果没有安装,弹出dialog形式的分享时,则不会显示appName
PS:测试基于 小米 Mi3 + CM android 5.1.1 + Facebook SDK 4.8.0
0 0
- 【Android】Share via facebook with appName or without appName 有标签、无标签
- MooseFS中的APPNAME宏
- xcode attaching to appName
- appName多语言
- icon+appname+key
- Android获取程序路径 (/data/data/appname)
- 【Android】Gadle改变应用名称(appName)的两种方法
- 【Android】Gadle改变应用名称(appName)的两种方法
- 【Android】Share via whatsapp
- attaching to appname问题解决方法
- How to change appname or app icon for different flavor version?
- An App ID with Identifier 'com.domainName.AppName' is not available. Please enter a different string
- Android: how to share with Facebook (如何分享信息到facebook)
- Android组件:radio、checkbox、下拉列表(两种方式)、日期;界面不显示appname
- windows share files with linux via vitrualbox
- With or Without You
- With or Without You
- iOS开发问题---调试提示The certificate used to sign “appName” has either expired or has been revoked.
- SQlite第三方框架PLDatabase的使用
- 小记大学生涯、、、勿喷
- 简单jxl操作之jsp下载Excel
- cookie的了解
- 179. Largest Number
- 【Android】Share via facebook with appName or without appName 有标签、无标签
- 对Java多态性的理解
- 微服务实战(六):选择微服务部署策略
- eclipse启动无响应,停留在Loading状态
- Axis通过wsdd部署Web Service
- 15. 3Sum
- android改变屏幕分辨率
- 部署var包至远程服务器
- NYOj-236-心急的C小加