android - 当我必须使用 Intent 时,什么是 createChooser?我可以用这种方法做什么?

标签 android android-intent

我一直在查看 stackoverflow,但我没有找到关于什么是“createChooser”以及为什么我可以使用它的定义,以及在哪种情况下使用它是好的。

提前致谢。

最佳答案

例如:您的应用程序中有共享图片选项。

您可以这样定义 Intent :

Intent picMessageIntent = new Intent(android.content.Intent.ACTION_SEND);
picMessageIntent.setType("image/jpeg");

File downloadedPic =  new File(
    Environment.getExternalStoragePublicDirectory(
    Environment.DIRECTORY_DOWNLOADS),
    "q.jpeg");

picMessageIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(downloadedPic));

比你打电话时:

startActivity(picMessageIntent);  

将列出您手机上所有能够获取此图片的应用程序。

如果您想自定义该列表的标题,您可以像这样使用 createChooser:

startActivity(Intent.createChooser(picMessageIntent, "Send your picture using:"));

enter image description here

关于android - 当我必须使用 Intent 时,什么是 createChooser?我可以用这种方法做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10294308/

相关文章:

android - 从 Assets 文件夹创建的 SQLite DB 更新问题

android - Kotlin : How to use if-else like condition with let block for 'null' checks

java - 通过主屏幕替换技术了解 Android 上的自定义锁实现

android - 如何打开具有特定设置的 URL?

android - 如何从 URI 中获取完整的 URL?

android - 链接 Intent 安卓

android - 如何将一个大文件或多个文件发送到其他应用程序,并知道何时删除它们?

android - 在 Android 版本 4.4.2 中使用 GoogleDrive 时无法获取文件路径

android - 使用 AsyncTask 在线程之间传递的实例变量的行为是什么?

android - 在android可绘制中调整图像大小