ShareActionProvider为设备上的每个兼容应用程序提供共享。我想指定哪些应用程序我想允许共享,例如只有twitter和gmail。仅添加特定的应用程序以共享actionprovider
我该怎么做?
ShareActionProvider为设备上的每个兼容应用程序提供共享。我想指定哪些应用程序我想允许共享,例如只有twitter和gmail。仅添加特定的应用程序以共享actionprovider
我该怎么做?
谷歌不建议你分享到特定的应用程序,因为有各种不同的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在这个问题How to filter specific apps for ACTION_SEND intent (and set a different text for each app)的答案将做到这一点。
但是,如果您特别希望它是一个actionprovider下拉列表,我还没有找到这个解决方案。
This Works。但我想在shareactionprovider中有多个项目。我试图添加多个共享意图,但它不起作用。可能吗? – TrtG
哦,所以你想要弹出包含几个项目,如只是Facebook和Twitter?我不确定如果没有制作自己的弹出窗口,并且想要分享的每个应用都有一个按钮,那么您还需要知道每个要共享的应用的软件包名称。如果这有道理? – Danielle
是的,这很有道理,谢谢。 – TrtG