需要权限才能在Android网络视图中访问摄像头吗? [英] Need permission to access camera in Android web-view?

查看:74
本文介绍了需要权限才能在Android网络视图中访问摄像头吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Webview的帮助下在android studio中开发Web应用程序,但是遇到一些问题,我需要打开摄像机的访问权限,我该怎么做?我已在 AndroidManifest.xml中授予了以下权限

I am developing a Web App with the help of Webview in android studio but having some issue I need to have the access open the camera how can I do that I have given the following permission in AndroidManifest.xml

<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

打开相机我需要做些什么?

what should I need to do more to open the camera?

推荐答案

如果您针对Android 6.0及更高版本的应用添加了运行时权限

if your app targeting Android 6.0 and above than add runtime permission

从Android 6.0(API级别23)开始,用户在应用运行时(而不是在安装应用时)授予应用访问权限

使用下面的摄像头代码添加运行时权限

add runtime permission using below code for camera

String permission = Manifest.permission.CAMERA;
int grant = ContextCompat.checkSelfPermission(this, permission);
if (grant != PackageManager.PERMISSION_GRANTED) {
    String[] permission_list = new String[1];
    permission_list[0] = permission;
    ActivityCompat.requestPermissions(this, permission_list, 1);
}

然后处理这样的结果

 @Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
                                       @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (requestCode == 1) {
        if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            Toast.makeText(AccountClass.this,"permission granted", Toast.LENGTH_SHORT).show();  
             // perform your action here

        } else {
            Toast.makeText(AccountClass.this,"permission not granted", Toast.LENGTH_SHORT).show();
        }
    }

}

了解运行时权限

这篇关于需要权限才能在Android网络视图中访问摄像头吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆