Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 仅将特定应用添加到shareactionprovider_Android_Actionbarsherlock_Shareactionprovider - Fatal编程技术网

Android 仅将特定应用添加到shareactionprovider

Android 仅将特定应用添加到shareactionprovider,android,actionbarsherlock,shareactionprovider,Android,Actionbarsherlock,Shareactionprovider,ShareActionProvider为设备上的每个兼容应用程序提供共享。我想指定我想允许共享的应用程序,比如只允许twitter和gmail 我该怎么做呢?谷歌不建议你分享给特定的应用,因为有各种不同的Twitter客户端——最好让人们选择他们想要分享的地方 但是,以下代码将通过按下按钮向twitter发送消息“hello twitter” String message = "hello Twitter"; try { //try to open the official twitt

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


我该怎么做呢?

谷歌不建议你分享给特定的应用,因为有各种不同的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);
}

希望这能有所帮助。

如果您不介意只使用弹出窗口,那么dacoinminster在这个问题上的回答就可以了


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

这很有效。但是我想在shareactionprovider中有多个项目。我尝试添加多个共享意图,但没有效果。有可能吗?哦,那么你希望弹出窗口包含几个项目,比如facebook和twitter?我不确定如果不制作自己的弹出窗口(每个应用程序都有一个按钮)就可以实现这一点——你还需要知道每个应用程序的程序包名称。这有意义吗?