仅将特定应用程序添加到shareactionprovider

时间:2014-01-23 16:57:33

标签: android actionbarsherlock shareactionprovider

ShareActionProvider为设备上的每个兼容应用程序提供共享。我想指定哪些应用程序允许共享,例如仅限twitter和gmail。

我该怎么做?

2 个答案:

答案 0 :(得分:1)

Google不建议您与特定应用分享,因为有各种不同的Twitter客户端 - 最好让人们选择他们想要分享的地方。

但是,以下代码会在按下按钮时向Twitter发送消息“hello twitter”。

String message = "hello Twitter";

try {
    //try to open the official twitter app
    Intent sharingIntent = new Intent(Intent.ACTION_SEND);
    sharingIntent.setType("text/plain");
    sharingIntent.putExtra(
            android.content.Intent.EXTRA_SUBJECT, "Subject");
    sharingIntent.putExtra(Intent.EXTRA_TEXT, message);
    sharingIntent.setPackage("com.twitter.android");
    startActivity(sharingIntent);

} catch (Exception e) {
    //fallback on opening an internet browser
    Log.e("Danielle", "exception=" + e.toString());
    Intent i = new Intent();
    i.putExtra(Intent.EXTRA_TEXT, message);
    i.setAction(Intent.ACTION_VIEW);
    i.setData(Uri
            .parse("https://mobile.twitter.com/compose/tweet"));
    startActivity(i);
}

希望有所帮助。

答案 1 :(得分:0)

如果你只使用弹出窗口就可以了,那么dacoinminster在这个问题How to filter specific apps for ACTION_SEND intent (and set a different text for each app)中的答案就可以了。

但如果你特别希望它是一个actionprovider下拉列表,我也没有找到这个解决方案。

相关问题