我试图从我想要的应用程序中调用共享方法,而不仅仅是调用允许共享的所有应用的列表。我正在使用此代码来调用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
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();
}
希望它能帮助您