Below are the problems and solutions for permission denied I encountered when learning Android development
1. net: ERR_CACHE_MISS
Solution
Add permission to the following:
<manifest xmlns:andro package=""> <uses-permission android:name=""/> ... </manifest>
2. Read and write to external storage (files in mobile phone)
Solution
First of all, permission is also required to be added to
<manifest xmlns:andro package=""> <uses-permission android:name=".READ_EXTERNAL_STORAGE"/> <uses-permission android:name=".WRITE_EXTERNAL_STORAGE"/> <!-- The following line of code is also very important,Don't forget to add--> <application ... android:requestLegacyExternalStorage="true">...</application> </manifest>
Secondly, it is necessary to enable this app to obtain storage permissions. You can set it in the mobile phone -> Settings -> corresponding app to allow the app to read the mobile phone memory (the easiest way).
A better way (the formal way) is to check if the app has permission to read memory when opening it. If not, the user is prompted to enable it and write a snackbar to point to the settings of this app. The code is as follows:
/** * Check whether the app has storage permissions. If not, remind the user to enable permissions. */ public void handlePermission() { // Check whether it is turned on // (xxx is permission, added according to your own needs) if ((this, .WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { (this, "Permission has been allowed", Toast.LENGTH_SHORT).show(); } else { (this, "ask for permission",Toast.LENGTH_SHORT).show(); // Request permission (this, new String[] {.WRITE_EXTERNAL_STORAGE}, 1); (TAG, "handlePermission: has aksed"); } }
This function can be placed in the onCreate() method or listener() according to your needs. For example, if placed in onCreate(), the user will be reminded to enable the corresponding permissions when opening this page.
This is the article about the reasons and solutions for Android permission denied. For more related content on Android permission denied, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!