简体   繁体   English

清除意图动作默认值

[英]Clear intent action default

I am launching the camera app in normal or secure mode depending on what gesture is performed using my app but once the user selects the app and taps Always then there is no option to change the defaults, even from the settings menu in Android. 我会根据使用我的应用程序执行的手势在正常或安全模式下启动相机应用程序,但是一旦用户选择了该应用程序并点击“始终”,就无法更改默认设置,即使是从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);

Is there a workaround? 有解决方法吗? I want to show the camera selection dialog once again so that the user can change his choice. 我想再次显示“摄像机选择”对话框,以便用户可以更改其选择。

If you want to present the app chooser even if the user has a default activity selected for the task, use Intent.createChooser() . 如果即使用户为任务选择了默认活动,也要显示应用选择器,请使用Intent.createChooser()

From the Android developer guide : 来自Android开发人员指南

If you call Intent.createChooser(), passing it your Intent object, it returns a version of your intent that will always display the chooser. 如果您调用Intent.createChooser()并将其传递给您的Intent对象,它将返回您的Intent版本,该版本将始终显示选择器。 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. 如果没有匹配的应用程序,Android将显示系统消息。
  • You can specify a title for the chooser dialog. 您可以为选择器对话框指定标题。

You should also check the documentation for ACTION_CHOOSER for guidelines on where this is appropriate or not (Intent.createChooser() is just a convenience method for this). 您还应该查看ACTION_CHOOSER的文档,以了解在何处适当使用该准则(Intent.createChooser()仅是一种便捷方法)。

startActivity(Intent.createChooser(senderIntent, "Title here"));

它将始终显示选择器对话框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM