Android Request Permission annotation conditional - android

I am building an SDK API with beacons integration which requires Bluetooth scan permission for android 12 and above. So, I added annotation for the API like this:
#RequiresPermission(allOf = [Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.BLUETOOTH_SCAN])
fun enableBeaconScan()
When I add this, I am getting a warning:
Is there a way to restrict this permission only for the supported android versions and get rid of this warning?

you can use this annotation
#TargetApi(Build.VERSION_CODES.S)

Related

Strict Secure Cookie policy error in AdMob after updating to Android 11

After updating my app to compile with API level 30 (Android R, 11), I can't see AdMob test ads, and I'm receiving this error in the log:
Strict Secure Cookie policy does not allow setting a secure cookie for
http://googleads.g.doubleclick.net/ for apps targeting >= R. Please
either use the 'https:' scheme for this URL or omit the 'Secure'
directive in the cookie value.
I'm using the last AdMob version, and I don't have "org.apache.http.legacy" references in Gradle or manifest.
This might come from the webview cookie_manager.cc.
Also this: https://www.chromestatus.com/feature/5633521622188032
Same question here: How to resolved http and Site Behavior: Navigation error in android app?
It might be temporarily broken, unless they'd set the cookie as expected.
I'm using flutter and I'm facing the same issue while implementing banner test ads.
Just add the below in android manifest file under application:
android:usesCleartextTraffic="true"
and issue will be resolved.

Error using getContex and ContextCompat.checkSelfPermission() after update AS

I have updated my Android Studio to 3.4.1 and Im using target sdk version 28 . I run my previous project. Now I got many errors : getContex or ContextCompat.checkSelfPermission() is not defined.
UPDATE: here is the error:
error: cannot find symbol method getContext()
error: cannot find symbol method shouldShowRequestPermissionRationale(MainActivity,String)
How can I fix it?
ContextCompat.checkSelfPermission(Context context, String permission) method is used simply for checking whether you are having requested permission available for your app or not.
If your app needs a dangerous permission, you must check whether you have that permission every time you perform an operation that requires that permission. Beginning with Android 6.0 (API level 23), users can revoke permissions from any app at any time, even if the app targets a lower API level.
ActivityCompat.requestPermissions(Activity activity, String[] permissions,int reqCode) method is used for requesting permissions
Thanks for all answers.I add implementation 'com.android.support:support-v4:28.0.0' to build.gradle. Before it I just have implementation 'com.android.support:appcompat-v7:28.0.0' and It works.

cannot resolve method 'getSerial()'

i'm trying to get Serial Number in android
in this answer Thaussma said that
in Android 8 and later (>= SDK 26) use android.os.Build.getSerial()
which requires the dangerous permission READ_PHONE_STATE. Using
android.os.Build.SERIAL returns android.os.Build.UNKNOWN.
but when i tried android.os.Build.getSerial() with required permission i got cannot resolve method 'getSerial()' error

Adding the Layer library dependency in Android suppresses requestPermissions dialog

I made a very, very small demo app reproducing the bug on a Nexus 5 running Android version 6.0.1. The app is on github here: https://github.com/lexi-sr/LayerPermission
I recently added 2 commits in which it targets API 23 and requests permissions at run time, but it still didn't work.
In these 2 commits, it has these settings:
Target SDK: 23
compiles Layer 0.20.3
1) In the commit "Removing layer dependency allows the popup dialog to request the perm…", where it does NOT have layer dependency:
The method ActivityCompat.requestPermissions opens a dialog that requests the Contacts permission, and a log statement within the onRequestPermissionsResult method logs that the permission has been granted.
2) In the commit "Requesting permissions does not work" where it DOES have layer dependency:
ActivityCompat.requestPermissions does not open up any dialogs, but a log statement within onRequestPermissionsResult still prints, logging that it does not have the permission.
It seems like adding the layer dependency is suppressing the ability to request for permissions at run time. Why is this happening?
Luckily, the layer support team was able to help me with this. It solved my problem in the demo app (which targeted SDK 23) and my real app (which targeted SDK 22, to avoid requesting permissions at runtime). After I put tools:node="replace" into my uses-permission line for GET_ACCOUNTS, the pop up dialog was able to appear and grant the permission in the demo app, and the permission was no longer missing in the real app which targeted SDK 22.
Here is the detailed explanation from the Layer support team:
The layer SDK requests the GET_ACCOUNTS permission using a
maxSdkVersion of 18. It would appear that when the manifests get
merged this is overwriting the permission request in your manifest,
thus not requesting that permission for 19+. Could you try appending
tools:node="replace" to the permission in your app's manifest? The
line should read as:
<uses-permission android:name="android.permission.GET_ACCOUNTS" tools:node="replace" />
See here for the maxSdkVersion documentation:
http://developer.android.com/guide/topics/manifest/uses-permission-element.html
See here for the tools:node documentation:
http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger#TOC-tools:node-markers
Peter

Looking for a list of methods that cause Android API 23 (Marshmallow) to throw the permission needed SecurityException

Has the Android team posted a list of methods that cause Android API 23 (Marshmallow) to throw a SecurityException when a permission is needed?
Something like:
RECORD_AUDIO throws SecurityException on the following methods:
SpeechRecognizer.startListening
etc.
As of now, we're just wandering around our app trying to best-guess when this will happen. Some devices are throwing this exception when others aren't -- as well as the emulator.
EDIT:
Issue solved. This is a problem with Xamarin Studio as it does not flag function calls that need a permissions check. I recently created a project in Android Studio and it red-underlines function calls that need a permissions check.

Categories

Resources