【发布时间】:2011-10-06 15:36:33
【问题描述】:
我正在我的 Android 应用程序上实现共享功能。我已经集成了一个意图选择器来共享文本类型的消息。现在,我想创建两个快捷方式:一个访问用户的 Facebook 帖子页面,另一个访问他的 Twitter 帖子页面。 (就像选择者所做的那样)
我发现了这个有用的主题:launch facebook app from other app 并尝试使用 ADB shell 命令找到正确的单词 (fb://word),但我不知道 ("publish"、"publishing"、"post" 、“分享”、“分享”不起作用)。
然后,当我单击 Facebook 或 Twitter 时,我尝试在意图选择器上捕获创建的意图(通过日志)。我发现:
“开始:Intent { act=android.intent.action.SEND typ=text/plain flg=0x3000000 cmp=com.twitter.android/.PostActivity (has extras) } from pid 17575”用于 Facebook,以及
"Starting: Intent { act=android.intent.action.SEND typ=text/plain flg=0x3000000 cmp=com.facebook.katana/.ShareLinkActivity (has extras) } from pid 17575" for Twitter。
我使用以下代码(在按钮的 onClick() 方法上)创建了这些意图:
Intent fbIntent = new Intent(Intent.ACTION_SEND);
fbIntent.setType("text/plain");
fbIntent.setFlags(0x3000000);
fbIntent.setComponent(new ComponentName("com.facebook.katana", ".ShareLinkActivity"));
fbIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_text));
startActivity(fbIntent);
我也试过这种方式:
Intent twitterIntent = new Intent(Intent.ACTION_VIEW);
twitterIntent.setAction("android.intent.action.SEND");
twitterIntent.setFlags(0x3000000);
twitterIntent.setType("text/plain");
twitterIntent.setComponent(new ComponentName("com.twitter.android", ".PostActivity"));
twitterIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_text));
startActivity(twitterIntent);
但即使日志看起来相同,也不会发生任何事情。
有什么想法吗?
【问题讨论】:
-
什么是“0x3000000”?