Jan*_*usz 80
Paresh Mayani的回答大多是正确的.只需使用Broadcast Intent让系统和所有其他应用程序选择内容将以何种方式共享.
要共享文本,请使用以下代码:
String message = "Text I want to share.";
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_TEXT, message);
startActivity(Intent.createChooser(share, "Title of the dialog the system will open"));
Run Code Online (Sandbox Code Playgroud)
Ion*_*gru 32
是的,你可以...你只需要知道应用程序的确切包名:
你可以像这样创建意图
Intent intent = context.getPackageManager().getLaunchIntentForPackage(application);
if (intent != null) {
// The application exists
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setPackage(application);
shareIntent.putExtra(android.content.Intent.EXTRA_TITLE, title);
shareIntent.putExtra(Intent.EXTRA_TEXT, description);
// Start the specific social application
context.startActivity(shareIntent);
} else {
// The application does not exist
// Open GooglePlay or use the default system picker
}
Run Code Online (Sandbox Code Playgroud)
Par*_*ani 28
我想你想给分享按钮,点击哪个合适的媒体/网站选项应该与它分享.在Android中,您需要创建createChooser相同的内容.
分享文字:
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "This is the text that will be shared.");
startActivity(Intent.createChooser(sharingIntent,"Share using"));
Run Code Online (Sandbox Code Playgroud)
共享二进制对象(图像,视频等)
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse(path);
sharingIntent.setType("image/png");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
Run Code Online (Sandbox Code Playgroud)
仅供参考,以上代码均来自使用ACTION_SEND Intent在Android中共享内容
用这个
Facebook - "com.facebook.katana"
Twitter - "com.twitter.android"
Instagram - "com.instagram.android"
Pinterest - "com.pinterest"
SharingToSocialMedia("com.facebook.katana")
public void SharingToSocialMedia(String application) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_STREAM, bmpUri);
boolean installed = checkAppInstall(application);
if (installed) {
intent.setPackage(application);
startActivity(intent);
} else {
Toast.makeText(getApplicationContext(),
"Installed application first", Toast.LENGTH_LONG).show();
}
}
private boolean checkAppInstall(String uri) {
PackageManager pm = getPackageManager();
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
return true;
} catch (PackageManager.NameNotFoundException e) {
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
106879 次 |
| 最近记录: |