我想在导航抽屉上做一个分享按钮,当用户触摸按钮时,它会打开那个黑色抽屉,上面有所有应用程序的列表,用户可以分享Google play链接的应用程序。有没有通用的代码模板?我找到的唯一答案是只在一个应用程序上分享它,比如Facebook,这似乎是无用的,因为不是每个人都使用Facebook。
发布于 2015-02-11 03:09:26
使用共享意图http://developer.android.com/training/sharing/send.html
示例代码
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);发布于 2015-12-20 13:13:03
您可以通过使用ACTION_SEND调用隐式意图来发送内容。
要发送图像或二进制数据:
final Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/jpg");
final File photoFile = new File(getFilesDir(), "foo.jpg");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(photoFile));
startActivity(Intent.createChooser(shareIntent, "Share image using"));将图像与文本一起发送。这可以通过以下方式完成:
String text = "Look at my awesome picture";
Uri pictureUri = Uri.parse("file://my_picture");
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, text);
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Share images..."));共享多个镜像可以通过以下方式完成:
Intent shareIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
shareIntent.setType("image/*");发布于 2021-01-04 21:04:31
这是Kotlin版本
val sendIntent: Intent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, "This is my text to send.")
type = "text/plain"
}
val shareIntent = Intent.createChooser(sendIntent, null)
startActivity(shareIntent)https://stackoverflow.com/questions/28439439
复制相似问题