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
Related
My app (code on GitHub) was rejected by Google Play with reason:
Please remove the background location permission requested and submit an update to your app.
However, my app does not declare the ACCESS_BACKGROUND_LOCATION permission:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.READ_SYNC_STATS" />
<uses-permission android:name="android.permission.REORDER_TASKS" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="com.google.android.apps.photos.permission.GOOGLE_PHOTOS" />
<uses-permission android:name="android.permission.SET_WALLPAPER"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
I first suspected Mapbox, as my app includes these libraries:
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.1.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-localization-v8:0.11.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-scalebar-v9:0.4.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-telemetry:6.1.0'
However my app checks location only when the app is running fully visible on the screen.
Also, the merged manifest shown by Android Studio does not include ACCESS_BACKGROUND_LOCATION:
It seems that setting android:minSdkVersion="29" would circumvent the issue, but I can't do it as I have thousands of important users below that.
I also tried adding a popup disclaiming that the app uses location in the background (even though it does not), but that gets rejected too, with this reason:
It is possible to deliver a similar experience without access to location in the background.
Question: What could be making someone think that I use location in the background?
From the official Privacy changes in Android 10
Access granted automatically when targeting Android 9 or lower
If your app runs on Android 10 or higher but targets Android 9 (API level 28) or lower, the platform applies the following behavior:
If your app declares a <uses-permission> element for either ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION, the system automatically adds a element for ACCESS_BACKGROUND_LOCATION during installation.
If your app requests either ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION, the system automatically adds ACCESS_BACKGROUND_LOCATION to the request.
Access when device is upgraded to Android 10
If a user grants your app access to device location – either ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION – then upgrades their device from Android 9 to Android 10, the system automatically updates the set of location-based permissions granted to your app. The set of permissions that your app receives after the upgrade depends on its target SDK version and its defined permissions, as shown in the following table: here
In other words, it all depends on your Target platform version.
Hello i have an app in play console and receive the next notification:
We have detected that your manifest file contains the permission REQUEST_INSTALL_PACKAGES.
Google explain the steps for legalize it, but i don't have this permission in my manifest and I don't use functions to install files either ,i don´t know the real reason for this message and i'm afraid that my app will be removed from the store if I don't take the necessary measures.
Does anyone have more information on this or know what google might actually be detecting in my app?
This are the permissions in the manifest:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission
android:name="com.google.android.gms.permission.AD_ID"
tools:node="remove" />
Edit: I receive a new mail from Google , they specify the permission belongs to HMS core, i search in the huawei developers and Huawei release some update of all their libraries fixing or eliminating the permission from the code, it seem to solve the problem , i will upload a new version to play console hoping finishing the issue
You are querying all packages with the package manager, this is no longer allowed since Android 8.0. If you don't see it in your manifest, you might want to check your merged manifest.
See more info here.
https://support.google.com/googleplay/android-developer/answer/12085295?hl=en
So i have an application that connect to bluetooth printer. It is fine and running on all devices except these devices:
Xiaomi redmi note 10 Pro (Updated to android 12 with MIUI 13.0.1)
Oppo Reno 5 4G (model: CPH2159) (Updated to android 12 with Color Os 13)
Regarding Google developer, android 12 using these three permission
android.permission.BLUETOOTH_CONNECT
android.permission.BLUETOOTH_SCAN
android.permission.BLUETOOTH_ADVERTISE
but when i tried to connect on my printer, i got this error that makes me pulls my hair out.
2022-03-21 09:23:49.039 29022-29206/com.xxxx.xxxxx E/BThermalPrinterPlugin: UID 10324 / PID 29022 lacks permission android.permission.BLUETOOTH
java.lang.SecurityException: UID 10324 / PID 29022 lacks permission android.permission.BLUETOOTH
at android.os.Parcel.createExceptionOrNull(Parcel.java:2425)
at android.os.Parcel.createException(Parcel.java:2409)
at android.os.Parcel.readException(Parcel.java:2392)
at android.os.Parcel.readException(Parcel.java:2334)
at android.bluetooth.IBluetoothSocketManager$Stub$Proxy.connectSocket(IBluetoothSocketManager.java:227)
at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:404)
at id.kakzaki.blue_thermal_printer.BlueThermalPrinterPlugin.lambda$connect$1$id-kakzaki-blue_thermal_printer-BlueThermalPrinterPlugin(BlueThermalPrinterPlugin.java:544)
at id.kakzaki.blue_thermal_printer.BlueThermalPrinterPlugin$$ExternalSyntheticLambda1.run(Unknown Source:6)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:920)
is this sort of ROM/platform/device specific problem. android.permission.BLUETOOTH supposed to be used on android 11 and below because android 12 and above replaces it with android.permission.BLUETOOTH_CONNECT, right? then why i got those specific device errors in the first place?
i have tried in Samsung A52 with android 12 and got no problem at all.
i have added necessary permission on manifest
AndroidManifest.xml
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
and runtime permission request
var perm = arrayListOf(
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.CAMERA,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.RECORD_AUDIO,
Manifest.permission.READ_PHONE_STATE,
Manifest.permission.BLUETOOTH,
Manifest.permission.BLUETOOTH_ADMIN
)
//permission
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { // >= android 12
perm.add(Manifest.permission.BLUETOOTH_CONNECT)
perm.add(Manifest.permission.BLUETOOTH_SCAN)
perm.add(Manifest.permission.BLUETOOTH_ADVERTISE)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(
perm.toTypedArray(), ActivityBase.REQ_PERM
)
}
As you already found, Xiaomi seems to have an incorrect implementation of the Bluetooth spec.
I had the same problem as you do and solved it declaring android.permission.BLUETOOTH in AndroidManifest.xml, even for Android 12.
So, instead of adding the following line, which the documentation suggests:
<uses-permission android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="30" />
I added:
<uses-permission android:name="android.permission.BLUETOOTH" tools:remove="android:maxSdkVersion" />
I had to add the tools:remove attribute because the Bluetooth library I was using was adding the maxSdkVersion attribute already. So it was being included in my merged manifest even if I didn't add it myself.
Also note that adding this permission in the manifest didn't cause any further problems or permission prompts on other Android 12 devices like Samsung.
I think it is a Xiaomi/MIUI issues. To make it work, you can use with android:targetSdkVersion="30" and not with android:targetSdkVersion="31".
The following code snippet demonstrates how to declare Bluetooth-related permissions in your app if it targets Android 12 or higher:
<manifest>
<!-- Request legacy Bluetooth permissions on older devices. -->
<uses-permission android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"
android:maxSdkVersion="30" />
<!-- Needed only if your app looks for Bluetooth devices.
If your app doesn't use Bluetooth scan results to derive physical
location information, you can strongly assert that your app
doesn't derive physical location. -->
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<!-- Needed only if your app makes the device discoverable to Bluetooth
devices. -->
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<!-- Needed only if your app communicates with already-paired Bluetooth
devices. -->
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<!-- Needed only if your app uses Bluetooth scan results to derive physical location. -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
...
you can check more details here source.
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 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.