我正在Android应用程序上实现共享功能。我已经整合了一个意图选择器来共享文本类型的消息。现在,我想创建两个快捷方式:一个用于访问用户的Facebook帖子页面,另一个用于访问他的Twitter帖子页面。 (作为选择者)
我找到了这个有用的主题:launch facebook app from other app并尝试使用ADB shell命令找到正确的单词(fb:// word),但我无法弄清楚(“发布”,“发布”,“发布“,”分享“,”分享“不行”。
然后,当我点击Facebook或Twitter时,我试图捕捉意图选择器上创建的意图(通过日志)。我找到了:
“开始:意图{act = android.intent.action.SEND typ = text / plain flg = 0x3000000 cmp = com.twitter.android / .PostActivity(has extras)} from pid 17575”for Facebook,and
“开始:意图{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);
但即使日志看起来一样,也没有任何事情发生。
有什么想法吗?
答案 0 :(得分:9)
我认为你应该使用setClassName而不是setComponent。
intent.setClassName("com.facebook.katana", "com.facebook.katana.ShareLinkActivity");
intent.setClassName("com.twitter.android", "com.twitter.android.composer.ComposerActivity");
注意:最近的Twitter版本使用' com.twitter.android.composer.ComposerActivity '(而不是' com.twitter.android.PostActivity < / EM>')