gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-28 23:30:15 24 4
gpt4 key购买 nike

我一直在查看 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com