after migrating the codebase to android 12 target SDK 32, i am trying to get the value of the below settings key
bluetooth_name
but on pixel devices on android 12 i keep getting this crash
Fatal Exception: java.lang.RuntimeException: java.lang.SecurityException: Settings key: <bluetooth_name> is only readable to apps with targetSdkVersion lower than or equal to: 31
from what i've tried so far, there is no extra permission that is needed for this change, also it works completely fine on almost any other device
am i missing something?
There are new restrictions on Android 12, and Bluetooth requires some extra permissions
However, I don't think that it's a permissions issue -- you simply can't access that setting with Android 12 or higher. You'll need to use the BluetoothAdapter class to get the info you need:
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
String name = adapter.getName()
Related
I have a Xamarin.Forms app targeting Android API Level 30 (Android 11) which had Xamarin.Twilio.AudioSwitch v1.1.3 installed. The app is available in Play Store and was working fine till the time Android 12 was not released.
As soon as Android 12 became available, I got complaints from users using the BLE functionality of the app that they are not able to connect with BLE devices supported by the application.
The Android 12 users were getting the following exception:
java.lang.SecurityException:
at android.os.Parcel.createExceptionOrNull (Parcel.java:2437)
at android.os.Parcel.createException (Parcel.java:2421)
at android.os.Parcel.readException (Parcel.java:2404)
at android.os.Parcel.readException (Parcel.java:2346)
at android.bluetooth.IBluetooth$Stub$Proxy.getRemoteName (IBluetooth.java:5470)
at android.bluetooth.BluetoothDevice.getName (BluetoothDevice.java:1889)
at crc....Adapter_Api21BleScanCallback.n_onScanResult (Native Method)
at crc....Adapter_Api21BleScanCallback.onScanResult (Adapter_Api21BleScanCallback.java:38)
at android.bluetooth.le.BluetoothLeScanner$BleScanCallbackWrapper$1.run (BluetoothLeScanner.java:646)
at android.os.Handler.handleCallback (Handler.java:938)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loopOnce (Looper.java:226)
at android.os.Looper.loop (Looper.java:313)
at android.app.ActivityThread.main (ActivityThread.java:8641)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:567)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1133)
The above exception occurs due to the Android 12 Bluetooth permission changes. But this is required only if the app targets API Level 31. But since my app targets API level 30, I was not expecting these changes to be required in my app.
On investigating the issue, I found out that the issue is due to the native Audio Switch v1.1.3 targeting Android API Level 31 (Android 12) as mentioned here: Twilio Audio Switch v1.1.3 but the Xamarin.Twilio.AudioSwitch v1.1.3 binding library specifies MonoAndroid 9.0 (https://www.nuget.org/packages/Xamarin.Twilio.AudioSwitch/1.1.3) due to which I was able to install it for a project targeting API Level 30.
Does this mean that if the app has a package which targets an Android API Level higher than the app itself, the target API level would be dynamically change to higher API level?
Now the problem that I am facing is that I am not able to get this issue fixed for the users who already have the app installed.
I did a downgrade of Xamarin.Twilio.AudioSwitch to v1.1.2 as the native Audio Switch v1.1.2 library targets Android API Level 30 (Android 11) and found that the issue gets solved for new installations of the app. If a user already using a previous version of my app which had the Audio Switch v1.1.3 package and updates to the latest version of app which is using Audio Switch 1.1.2, the user still faces the above exception.
Is there any way that this can be fixed without making the app target Android API level 31 (Android 12) as that would require significant changes to the app?
Note: Asking the users to reinstall the app is not an option for me.
--- This is only supposed to be needed if you target SDK 31 (but need legacy Bluetooth support), but its worth a try ---
Close solution.
In a text editor, edit file YourProject.Android/Properties/AndroidManifest.xml, with changes below.
Rebuild solution.
CHANGE 1:
Bluetooth permissions, point 4., recommends:
Add android:maxSdkVersion="30" to each declared Bluetooth-related permission. Example from doc's code snippet:
<!-- 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" />
Perhaps this will clear whatever the OS is remembering re your app's Bluetooth access.
CHANGE 2 (experiments):
EITHER: REMOVE any Bluetooth permissions that were added in SDK 31. ONLY list permissions that existed in SDK 30.
OR: list the permissions app WOULD need if targeted SDK 31, but add android:maxSdkVersion="30", similar to above.
Also consider point 5.:
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"
android:usesPermissionFlags="neverForLocation" />
maybe as:
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"
android:maxSdkVersion="30"
android:usesPermissionFlags="neverForLocation" />
What we are doing here is not standard -- "should" simply be ignored on a "target SDK 30" app -- it is an attempt to get OS to clear something it is remembering related to this app.
Hypothesis is that during OS upgrade, OS noticed which apps were using Bluetooth in a way that required additional permissions [due to Twilio.AudioSwitch v1.1.3], and marked them as needing those additional permissions. But then failing when feature used, because permission not declared in manifest.
No, it can't be changed dynamically you have to change it from gradle by yourself.
I am using xammp server for php on localhost , i was working before update (i think), but now http connection gives me an exception:
W/System.err: java.io.IOException: Cleartext HTTP traffic to
192.168.0.105 not permitted
i have tried then to add android:usesCleartextTraffic="true" on Application for AndroidManifest , but also a next error:
Attribute usesCleartextTraffic is only used in API level 23 and higher (current min is 17)
I want to keep support to API 17, and when releasing my app I will use https on a public server, what can I do for now?
You don’t have to set minSdkVersion or targetSdkVersion of your app to 23 (Android Marshmallow) to use android:usesCleartextTraffic. On older platforms, this attribute is simply ignored and thus has no effect.
Reference - https://android-developers.googleblog.com/2016/04/protecting-against-unintentional.html?m=1
I am confused about the target build and sdk usage
Lets say I have this code
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
//do xyz
}
Let say that I built against API 19 (kitkat) and my target api in manifest is 19 and my minimum supported api is 9
Now if a device with API 9 runs the above code, will it crash? I expect the answer is yes becasuse it will not understand what Build.VERSION_CODES.KITKAT means. However, what's the point of the check above then in first place?
Please help clarify this
Thank you
It won't crash. Simply the code within the if won't be executed. Build.VERSION_CODES.KITKAT is a constant field, and as you can read here, the constant fields are replaced with the numbers themselves by the compiler.
lesser versions of android will use the support library, if the check for kit-kat fails, it will revert to the closest possibkle form that version supports.... via the support library...
you cannot run you app on anything less than the minimum version, but it will find a way to run with less than the target version as long as its aboe the minimum
No, it won't crash, because its Build.VERSION.SDK_INT value is 9. It simply will not enter inside your if clause. Only devices that have API version 19 or above will run your code inside the if. Build.VERSION_CODES.KITKAT is equal to 19.
The code you posted won't crash because the class Build is created and compiled for every build of your app (as the R file) depending of the target API you set in the manifest
As you setup your target API to 19, the Build class will contain the field Build.VERSION_CODES.KITKAT because it exists starting from API level 19.
In the sample AudioFxDemo.java, provided with the SDK, I get a
java.lang.RuntimeException: Cannot initialize Visualizer engine, error: -4
when trying to create the android.media.audiofx.Visualizer
mVisualizer = new Visualizer(mMediaPlayer.getAudioSessionId());
(AudioFxDemo.java:173).
As far as I can see, the error originates in the native code, (lines 266 ff.) An error also happens when trying to create the android.media.audiofx.Equalizer:
mEqualizer = new Equalizer(0, mMediaPlayer.getAudioSessionId());
(AudioFxDemo.java:98)
I get a
java.lang.IllegalArgumentException: Effect type: 0bed4300-ddd6-11db-8f34-0002a5d5c51b not supported.
I have declared the following permissions for my project:
<uses-permission android:name="android.permission.RECORD_AUDIO"
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
Any ideas what might be going wrong here?
It seems to be a problem with the API level. I have no problems on Gingerbread (API Level 10). I have only tested on virtual devices.
This seems to be an issue with the Emulator. I have tested on an actual device running Android 4.0.3 and it worked just fine.
it seems issue on some android devices. I got this crash http://pastebin.com/7kqPbxkV on Lenovo a369i SDK version 17. For now only thing i`ve found is to check if equalizer effect is supported on device:
boolean supports_equalizer=false;
AudioEffect.Descriptor [] effects = Equalizer.queryEffects();
for (AudioEffect.Descriptor lDescriptor:effects){
if (Build.VERSION.SDK_INT>=18) { //Equalizer present only starting with API 18. Cam try to hardcode its UUID
if (AudioEffect.EFFECT_TYPE_EQUALIZER.equals(lDescriptor.uuid)){
supports_equalizer=true;
}
}
}
While running my application i am getting the below given warning and application went force close.
[2011-10-17 12:09:09 - LunarLander] WARNING: Application does not specify an API level requirement!
[2011-10-17 12:09:09 - LunarLander] Device API version is 9 (Android 2.3.1)
How to resolve this. I created another emulator with API level 10, then also i am getting the same error.
I am sure you forget to define the API level inside the AndroidManifest.xml file, define it as:
<uses-sdk android:minSdkVersion="5"
android:maxSdkVersion="10"
android:targetSdkVersion="8"/>
You should define the API level of your application in manifest file. I think you forgot to that. Launch the application according to that.
Just looking at that error you need to specify an API level for your application:
http://developer.android.com/guide/appendix/api-levels.html