我正在尝试从我想要的应用程序调用共享方法,而不仅仅是允许共享的所有应用程序的调用列表。我正在使用此代码来调用twitter分享:
String tweetUrl =
String.format("https://twitter.com/intent/tweet?text=%s&url=%s",
"Tweet text", "https://www.google.fi/");
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(tweetUrl));
// Narrow down to official Twitter app, if available:
List<ResolveInfo> matches = getPackageManager().queryIntentActivities(intent, 0);
for (ResolveInfo info : matches) {
if (info.activityInfo.packageName.toLowerCase().startsWith("com.facebook")) {
intent.setPackage(info.activityInfo.packageName);
}
}
startActivity(intent);
这适用于facebook:
String fullUrl = "https://m.facebook.com/sharer.php?u=..";
try {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setClassName("com.facebook.katana",
"com.facebook.katana.ShareLinkActivity");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "your title text");
startActivity(sharingIntent);
} catch (Exception e) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(fullUrl));
startActivity(i);
}
但它只是打开浏览器,而不是安装在手机上的facebook应用程序
并且不知道如何为Vk做这件事
答案 0 :(得分:0)
对于Facebook我知道只与这个Facebook提要对话分享
https://developers.facebook.com/docs/android/share
或
使用此浏览器代码
Session.openActiveSession(this, true, new Session.StatusCallback()
{
@Override
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
share(session);
}
}
});
}
private void share(Session mySession) {
String message = "bla";
Bundle bundle = new Bundle();
bundle.putString("caption", "caption");
bundle.putString("description", message);
bundle.putString("link", "link");
bundle.putString("name", "title");
bundle.putString("picture", "");
new WebDialog.FeedDialogBuilder(this, mySession, bundle).build().show();
}
希望它能帮到你