Mah*_*eie 5 android facebook sharing android-intent
我使用intent和Action.SEND在社交网络上分享我的自定义消息,如WhatsApp,twitter,Facebook和GMail.Gmail和除Facebook以外的其他应用程序一切正常!如何自定义我的代码以在Facebook上分享内容?我在Facebook上使用Facebook SDK分享没问题,但我想用意图来做.
这是我用的:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, knowTitle+"Read the full article via MomsApp by EnfaMama A+ at http://meadjohnsonasia.com.my/mobileapp");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "I just read "+knowTitle);
sendIntent.setType("*/*");
startActivity(Intent.createChooser(sendIntent, "Share Your Favorite Article"));
Run Code Online (Sandbox Code Playgroud)
我所做的实际上是拦截所选择的目标操作者的目标,你可以通过使用你的actionprovider来做到这一点.假设你创建了一个带有onclick的项目启动了intent.为此,您可以实例化一个actionprovider来执行此操作.这个actionprovider可以有一个setOnShareTargetSelectedListener来拦截你想要以不同方式处理的任何意图(或者根本不是^^).请参阅以下代码,了解如何配置actionprovider.
actionProvider.setShareIntent(createShareIntent());
actionProvider.setOnShareTargetSelectedListener(new OnShareTargetSelectedListener(){
@Override
public boolean onShareTargetSelected(ShareActionProvider source,
Intent intent) {
if ("com.facebook.katana".equals(intent.getComponent().getPackageName()) && mfacebooksharer != null) {
mfacebooksharer.shareStatus(subject, text);
return true;
}
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
每当选择Facebook时,我都会使用我的mfacebooksharer来处理意图并遵循facebook API.当然,actionrpovider需要有一个意图.(就像你想要有意图一样).我使用下面的方法来创建意图.
private Intent createShareIntent() {
intentsetter.setIntentleave(true);
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, text);
return shareIntent;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10081 次 |
| 最近记录: |