我一直在查看 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:"));
关于android - 当我必须使用 Intent 时,什么是 createChooser?我可以用这种方法做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10294308/