默认在包中声明权限 CAMERA

Declared permisisons CAMERA in package by default

当我第一次安装我的应用程序并尝试使用我的相机时,它没有请求许可

我的权限方法

public boolean hasPermissionInManifest(Context context, String permissionName) {
    final String packageName = context.getPackageName();
    try {
        final PackageInfo packageInfo = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_PERMISSIONS);
        final String[] declaredPermisisons = packageInfo.requestedPermissions;
        if (declaredPermisisons != null && declaredPermisisons.length > 0) {
            for (String p : declaredPermisisons) {
                if (p.equals(permissionName)) {
                    return true;
                }
            }
        }
    } catch (PackageManager.NameNotFoundException e) {

    }
    return false;
}

当我调试我的应用程序时,我发现 CAMERA 权限出现在 declaredPermisisons

AndroidManifest.xml

 ...
 <uses-permission android:name="android.permission.INTERNET" />
 <uses-feature android:name="android.hardware.camera" android:required="false" />
 ...

注意:在 declaredPermisisons

中找到的权限

我不知道为什么你的代码不起作用,但这是我用来获得许可的:

public class MainActivity extends AppCompatActivity {
    private static final int REQUEST_PERMISSION_CODE = 1000;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if(!checkPermissionFromDevice())
            requestPermission();
    }
    private void requestPermission() {
        ActivityCompat.requestPermissions(this,new String[]{
                Manifest.permission.CAMERA
        },REQUEST_PERMISSION_CODE);
    }
    private boolean checkPermissionFromDevice() {
        int camera = ContextCompat.checkSelfPermission(this,Manifest.permission.CAMERA);
        return camera ==PackageManager.PERMISSION_GRANTED;
    }
}