Skip to content Skip to sidebar Skip to footer

Java.lang.SecurityException: Permission Denial: Requires Com.huawei.android.launcher.permission.WRITE_SETTINGS

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 errors .

Solution 1:

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


Post a Comment for "Java.lang.SecurityException: Permission Denial: Requires Com.huawei.android.launcher.permission.WRITE_SETTINGS"