I'm trying to modify some settings on my phone through the app but I keep getting
this error:
java.lang.SecurityException: Permission denial: writing to settings requires android.permission.WRITE_SETTINGS
I have added this permission to my manifest but the error still remains.
Here is a snippet from my manifest:
<uses-permission
android:name="android.permission.MEDIA_CONTENT_CONTROL"
android:maxSdkVersion="11" />
<uses-permission
android:name="android.permission.CHANGE_CONFIGURATION"
android:maxSdkVersion="11" />
<uses-permission
android:name="android.permission.READ_PHONE_STATE"
android:maxSdkVersion="11" />
<uses-permission
android:name="android.permission.WRITE_SETTINGS"
android:maxSdkVersion="11" />
What is the problem here?
try like:
<uses-permission
android:name="android.permission.MEDIA_CONTENT_CONTROL"/>
<uses-permission
android:name="android.permission.CHANGE_CONFIGURATION" />
<uses-permission
android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-sdk
android:maxSdkVersion="11"
android:minSdkVersion="7"
android:targetSdkVersion="9" />
Note: It is not good to use android:maxSdkVersion in manifest. You can remove it.
Android doc says,
android:maxSdkVersion The highest API level at which this permission should be granted to your app. Setting this attribute is
useful if the permission your app requires is no longer needed
beginning at a certain API level.
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
This way, beginning with API level 19, the system will no longer grant
your app the WRITE_EXTERNAL_STORAGE permission.
In which SDK version do you run this code?
For Android version 11 & below, permission will be granted as per your code.
If you do not want to limit the permission with respect to particular sdk versions, remove the maxSdkVersion attribute.
Related
I am working for an application which uses BLE technology for pairing and IOT device and uses precises location to perform some specific task related to application requirements
Now, on Android 12 some device (I tested on SAMSUNG SM-M21)
it ended up in error
location permission missing (code 3)
whereas in another device like Realme, Mi it works fine as expected
After referring to the article
https://developer.android.com/guide/topics/connectivity/bluetooth/permissions
I already added these permission in the Manifest
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission
android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="30" />
<uses-permission
android:name="android.permission.BLUETOOTH_ADMIN"
android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
I am already requesting permission at runtime from user
If any more information is needed, please let me know. I will update the question accordingly.
I solved it by adding this to manifest
<uses-permission
android:name="android.permission.BLUETOOTH_SCAN"
android:usesPermissionFlags="neverForLocation" />
and at code level added a condition which add extra permission runtime only for Android 12 and above
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S){
//requesting permission only for Android 12 and above
Manifest.permission.BLUETOOTH_SCAN,
Manifest.permission.BLUETOOTH_CONNECT,
Manifest.permission.BLUETOOTH_ADVERTISE,
}
Note: other permissions also as normally requested
I have an application with following permissions in Manifest:
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
I manually enabled all permissions through Settings in an Android 11 mobile. However, if I use ActivityCompat.checkSelfPermission(this,(Manifest.permission.READ_PHONE_STATE)) to check if READ_PHONE_STATE permission has been granted, the result is always PERMISSION_DENIED.
I then used ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_PHONE_STATE), 102), which simply calls onRequestPermissionsResult with grant result PERMISSION_DENIED immediately.
I reproduced this on two Android 11 devices (one physical, one emulator), and I tried changing the package name, uninstalling and reinstalling the app etc.
I figured out what went wrong. One of the libraries I was including had this:
Library's Manifest
<uses-permission
android:name="android.permission.READ_PHONE_STATE"
android:maxSdkVersion="29" />
and even though I defined this permission in my app manifest, the maxSdkVersion got into my app.
The solution is to remove the maxSdkVersion property in your app:
App's Manifest
<uses-permission
android:name="android.permission.READ_PHONE_STATE"
tools:remove="android:maxSdkVersion" />
I'm setting up some permissions in my AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
I request the permission on runtime for all of those permissions.
But somehow the permission REQUEST_INSTALL_PACKAGES does not need to call requestPermission(). If I try to call it anyway, the popup never appears.
Is there a list of permissions i need to call at runtime?
My current android version is 8.0.0.
Thanks
Depends on type of permission you are requesting for. There are two kind of permissions in Android: Normal and Dangerous Permissions
If there are dangerous, you must request for it at runtime for API level 23 and above.
For more info you should read following documentation: https://developer.android.com/guide/topics/permissions/requesting.html#normal-dangerous
I have been trying to download a file from a url.
I have set the permissions in my android manifest file like so,
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
I am using a library called Adavnced WebView to handle downloads:
AdvancedWebView.handleDownload(view.getContext(),"https://static1.squarespace.com/static/57752cbed1758e541bdeef6b/t/58d91311ff7c50b172946ee5/1490621221735/PreKGuide_2017_English_032417+%281%29.pdf" , "abc.txt");
I get an error when I try to download. It clearly says that the app doesn't have permission to write to storage path. How can I set permission to write? What am I missing here? Please help.
java.lang.SecurityException: No permission to write to /storage/emulated/0/Download/abc.txt: Neither user 10147 nor current process has android.permission.WRITE_EXTERNAL_STORAGE.
You need the runtime permission, check the documentation.
I have to implement the new permissions system but i cant find some of the permissions i used earlier in my android apss:
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
For example: I used:
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
I can now replace this by
<uses-permission android:name="android.permission-group.CONTACTS" />
Because GET_ACCOUNTS is in the Group of CONTACTS.
But what about the other permissions i posted. They are not listed anywhere in the system permissions
The following permissions are not present in Android M.
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
Hence, you can request them using android:maxSdkVersion="22" in you uses-permission tag like this:
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" android:maxSdkVersion="22"/>
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" android:maxSdkVersion="22" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" android:maxSdkVersion="22"/>
You can read more about it here.
As for the last permission. That is:
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
You don't need to use the permission request for it, as it is allowed.
Looks like some permissions got deprecated in API level 23. If you are targeting API 23, then take care appropriately (i.e. request permission in runtime for "dangerous" permissions).
I think you should still keep them in manifest file for older SDKs.