java.lang.SecurityException: Permission Denial: requires com.huawei.android.launcher.permission.WRITE_SETTINGS

后端 未结 1 1790
春和景丽
春和景丽 2021-01-14 08:40

I am struggling with this problem when the application goes to run on the mobile phone HUAWEI ALE - 21 Android 6.0 API 23 . My application collapses and I take back those e

相关标签:
1条回答
  • 2021-01-14 09:04

    You need to check permission and request permission as below:

    Code example:

    // Here, thisActivity is the current activity
    if (ContextCompat.checkSelfPermission(thisActivity,
            "com.huawei.android.launcher.permission.WRITE_SETTINGS")
            != PackageManager.PERMISSION_GRANTED) {
    
        // Permission is not granted
        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
                "com.huawei.android.launcher.permission.WRITE_SETTINGS")) {
            // Show an explanation to the user *asynchronously* -- don't block
            // this thread waiting for the user's response! After the user
            // sees the explanation, try again to request the permission.
        } else {
            // No explanation needed; request the permission
            ActivityCompat.requestPermissions(thisActivity,
                    new String[]{"com.huawei.android.launcher.permission.WRITE_SETTINGS"},
                    MY_PERMISSIONS_REQUEST_WRITE_SETTINGS);
    
            // MY_PERMISSIONS_REQUEST_WRITE_SETTINGS is an
            // app-defined int constant. The callback method gets the
            // result of the request.
        }
    } else {
        // Permission has already been granted
    }
    

    For more details, see: https://developer.android.com/training/permissions/requesting

    0 讨论(0)
提交回复
热议问题