use bluetooth catch Need BLUETOOTH permission exception on Android12 - android

On Android12 devices, when using the bluetooth features, I get the flowing exception:
java.lang.SecurityException: Need BLUETOOTH permission
android.bluetooth.BluetoothHeadset.<init>(BluetoothHeadset.java:379)
android.bluetooth.BluetoothAdapter.getProfileProxy(BluetoothAdapter.java:3017)
My app's targetVersion is 29, and the related permissions have already declared in manifest.xml:
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
<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_CONNECT" />
This problem will not happen when the app first loading, but happened after turn on/off the Nearby Devices ipermission. It seem that it will clear the BLUETOOTH permission?

Related

Is there a way to get the BluetoothAdapter address if I do not plan to publish the app on Google play?

I am currently able to get the Bluetooth adapter mac address on devices with sdk from Marshmallow till Oreo.
However, starting Pie, the retrieved mac address is null.
The following method is working only till and including oreo.
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission
android:name="android.permission.LOCAL_MAC_ADDRESS"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="READ_PRIVILEGED_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH" />
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
String macAddress = Settings.Secure.getString(context.getContentResolver(), "bluetooth_address");
return macAddress;
I also tried to access BluetoothAdapter.getDefaultAdapter().getAddress() but it returns a fake Mac address like this "02:00:00:00:00"
I only ask the user for runtime permission for fine location. Should I ask for something else? Is there a way to achieve this on Pie and 10?
N.B: I know such app can not be uploaded to Google Play. I just want to implement this for testing purposes on personal devices.

Still getting the warning on Google Play Store that the App will be removed even though I've removed the permissions from Android Manifest

After the update to Google Policy I've removed the permissions for CALL_PHONE and SEND_SMS from my AndroidManifest.xml.
After uploading the latest version (yesterday) when I login to my Publish Dashboard, I'm still getting the warning that the application will be removed on 9th January.
These are the permissions I'm using in the Manifest now.
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
This is the warning I'm getting.
I've also noticed that if I check the Permissions used in the Google Play Listing, they are:
This app has access to:
Location
approximate location (network-based)
precise location (GPS and network-based)
Phone
read phone status and identity
Photos/Media/Files
read the contents of your USB storage
modify or delete the contents of your USB storage
Storage
read the contents of your USB storage
modify or delete the contents of your USB storage
Wi-Fi connection information
view Wi-Fi connections
Device ID & call information
read phone status and identity
Phone
directly call phone numbers
read phone status and identity
Other
receive data from Internet
mock location sources for testing
view network connections
full network access
prevent device from sleeping
read Google service configuration
Is this due to the READ_PHONE_STATE Permission? or does this take some time to update?
There might be some permission available in some other module or library you are using in project
Please remove manually from manifest like this
uses-permission android:name="android.permission.READ_SMS" tools:node="remove"
uses-permission android:name="android.permission.RECEIVE_SMS" tools:node="remove"
hope it will help

Bluetooth BLE readCharacteristic has some error

When I use BLE to read the characteristics of the time there are some errors,
Error as follows:
java.lang.SecurityException: Need BLUETOOTH_PRIVILEGED permission: Neither user 10168 nor current process has android.permission.BLUETOOTH_PRIVILEGED.
But I've alredy added appropriate permissions:
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" />
You have android.permission.BLUETOOTH_PRIVILEGED in your manifest, but are you sure it was granted? According to https://developer.android.com/reference/android/Manifest.permission.html#BLUETOOTH_PRIVILEGED "This is not available to third party applications"

push notifications not received on Xiomi when app not running

My app able to receive push notification when app is not running on Motorola with Lollipop, But Xiomi with Lollipop unable to receive notification if app is not running.
Anyhow if app is opened it is able to receive notifications.
Is there any problem in Xiomi phones ?
Here is my manifest file permissions:
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.example.localmarket.permission.C2D_MESSAGE" />
<permission
android:name="com.uignet.localmarket.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
I just found that Xiomi phones has a setting "Auto Start" for the apps to receive notifications in the background. It is disabled by default. That's the reason its not receiving notifications. Just enable it make it work. and also enable notifications for the apps installed.

My App is not compatible on WiFi only devices

I developed an android app which shows the caller's Telecom Location on Incoming Call.
I uploaded it on Google Play, but this app does not appear on WiFi only devices, it says your device is not compatible .
My Manifest permission details are below.
<uses-permission android:name="android.permission.READ_CALL_LOG"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
I doubt about following permissions
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
Which particular permissions are creating problem?
What is the solution.
Thanks
The google play store filters applications based on the permissions they require and the features available in the android device. So, your app will not show up in WiFi only devices because the app requires the CALL_PHONE permisssion and the MODIFY_STATE_PERMISSION.
The MODIFY_PHONE_STATE permission does not allow you to place calls but it implies that telephony is a requirement.
Source : https://developer.android.com/guide/topics/manifest/uses-feature-element.html#permissions
Hence, you should use the <uses-feature> element instead of the above mentioned permissions.
From Docs : You can disable filtering based on the implied feature by explicitly declaring the implied feature, in a element, with an android:required="false" attribute.
In your case :
<uses-feature android:name="android.hardware.telephony" android:required="false" />
But then you also need to ensure that you do not use any of the telephony related features before actually checking if it's available of not.
In the android app, for SDK >=5 , you should use :
PackageManager pm = this.getPackageManager();
boolean hasTelephony = pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
You are correct to suspect the following...
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
Certain permissions "imply" the necessity for certain hardware to exist. In other words, permissions relating to the phone require the device to have phone capabilities (obviously).
You can get around this by using the <uses-feature> element in the AndroidManifest.xml. This allows you to specify if the 'feature' is required or not.
Take a look at the documentation for <uses-feature-element>
In particular the Permissions that Imply Feature Requirements section which explains the requirements related to the <uses-permission> elements.
EDIT: One more thing - if a feature CAN be used but it's not REQUIRED, it is up to you to check for its availability in your code before attempting to use it otherwise you'll get unpredictable results or possible exceptions / crashes.

Categories

Resources