gpt4 book ai didi

java - 明确 Intent 操作默认值

转载 作者:太空宇宙 更新时间:2023-11-04 14:52:36 26 4
gpt4 key购买 nike

我正在正常或安全模式下启动相机应用程序,具体取决于使用我的应用程序执行的手势,但一旦用户选择应用程序并点击始终,则没有选项可以更改默认值,即使是从 Android 的设置菜单中也是如此.

camera_intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
secure_camera_intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
camera_intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
secure_camera_intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);

this.startActivity(camera_intent);
//this.startActivity(secure_camera_intent);

有解决办法吗?我想再次显示相机选择对话框,以便用户可以更改他的选择。

最佳答案

如果您想要显示应用选择器,即使用户为任务选择了默认 Activity ,请使用 Intent.createChooser() .

来自Android developer guide :

If you call Intent.createChooser(), passing it your Intent object, it returns a version of your intent that will always display the chooser. This has some advantages:

  • Even if the user has previously selected a default action for this intent, the chooser will still be displayed.
  • If no applications match, Android displays a system message.
  • You can specify a title for the chooser dialog.

您还应该查看 ACTION_CHOOSER 的文档有关何时适合或不适合的指南(Intent.createChooser() 只是一种方便的方法)。

关于java - 明确 Intent 操作默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23592748/

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