Android 11 调用手机系统摄像头新策略 IMAGE_CAPTURE

前言

android 11 调用系统摄像头有了新的策略,需兼容才可行


1、在Android11之前调用系统摄像头代码:

Intent captureIntent = new Intent("android.media.action.IMAGE_CAPTURE");
        if (captureIntent.resolveActivity(this.getPackageManager()) != null) {}

2、在Android11之后,captureIntent.resolveActivity(this.getPackageManager())方法将返回null,导致调用相机失败。

Starting in Android 11, only pre-installed system camera apps can respond to the following intent actions:

android.media.action.VIDEO_CAPTURE
android.media.action.IMAGE_CAPTURE
android.media.action.IMAGE_CAPTURE_SECURE
If more than one pre-installed system camera app is available, the system presents a dialog for the user to select an app. If you want your app to use a specific third-party camera app to capture images or videos on its behalf, you can make these intents explicit by setting a package name or component for the intent.

优化方案

在manifest中配置queries

<manifest package="your.package.name">
	<queries>
    	<intent>
        	<action android:name="android.media.action.IMAGE_CAPTURE" />
    	</intent>
	</queries>
</manifest>
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值