I was getting ready for runtime permissions on android M when I recently figured out that (at least on theGgalaxy S6 of my friend), still all permissions have to be confirmed at installation time (Google Play).
He has Android M, and sure you can revoke the permissions in the app settings now, but initially when you start the app after install, everything is granted.
I am kind of surprised, that's not the "Runtime Permissions" I was expecting.
Any hints on that? Did I miss something?
According to the doc:
This lesson describes how you implement permissions requests on apps that target API level 23 or higher, and are running on a device that's running Android 6.0 (API level 23) or higher. If the device or the app's targetSdkVersion is 22 or lower, the
system prompts the user to grant all dangerous permissions when they
install or update the app.
The runtime permissions will only take effect if you update the target SDK to 23
Related
My Android app targets SDK 28 and connects to Google Fit to upload data and read some other data. The app uses the HistoryAPI to read com.google.step_count.delta data.
This documentation claims that "com.google.android.gms.permission.ACTIVITY_RECOGNITION permission is converted into a pre-granted runtime permission" if the app targets SDK 28 but runs on SDK 29: https://developers.google.com/fit/android/authorization#android_permissions
I have added to the app's manifest like the documentation says to do.
When this Android app is on a device running Android 10 (SDK 29) and the user connects to Google Fit for the first time, I get a log saying:
There was a problem subscribing.com.google.android.gms.common.api.ApiException: 10: SecurityException: com.google.step_count.delta requires android.permission.ACTIVITY_RECOGNITION
Yet the documentation claims that this will be converted into a pre-granted runtime permission.
The team is not ready to migrate the app's target SDK to 29 just yet, so how can we continue to get com.google.step_count.delta data without this error?
I am assuming that this log means it didn't actually connect as there was no log statement that said:
Successfully subscribed to com.google.step_count.delta
Solved: In App Api Level 28 +
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>
The app should check if the permission is granted already:
if (ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.ACTIVITY_RECOGNITION)
!= PackageManager.PERMISSION_GRANTED) {
// Permission is not granted
}
To request the permission:
ActivityCompat.requestPermissions(thisActivity,
arrayOf(Manifest.permission.ACTIVITY_RECOGNITION),
MY_PERMISSIONS_REQUEST_ACTIVITY_RECOGNITION);
Learn more about requesting Android runtime permissions.
If your app targets SDK level 28 or below, it must specify the com.google.android.gms.permission.ACTIVITY_RECOGNITION permission in its manifest file.
Looks like the documentation was updated: https://developer.android.com/about/versions/10/privacy/changes#physical-activity-recognition
I was able to solve this by only using the API 28 permission in the manifest (com.google.android.gms.permission.ACTIVITY_RECOGNITION).
If the app was installed on a device running Android 10 (API 29), the system appears to correctly auto grant the permission android.permission.ACTIVITY_RECOGNITION.
Because the user can change this in settings (Settings > Apps & Notifications > Permission Manager > Physical Activity > specified app > deny), I was able to check the android.permission.ACTIVITY_RECOGNITION permission if the app was installed on a device running Android 10 (API 29).
Not sure if it helps for your issue but it helps us with similar problem.
First check if your app/user has Physical activity permitted - most probably not.
If you permit it - your code should run without exception.
Issue for us was how to detect that com.google.android.gms.permission.ACTIVITY_RECOGNITION is permitted (running in target sdk 28 on Android 10) - since call
PermissionCompat.isPermissionGranted(context,"com.google.android.gms.permission.ACTIVITY_RECOGNITION")
always returns true (even permission is denied)
workaround (for your app target sdk 28 runnning on Android 10) is to call requestPermission (instead of isPermissionGranted) which does not do anything when permission is granted and show dialog if not
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
PermissionCompat.requestPermission(activity, "com.google.android.gms.permission.ACTIVITY_RECOGNITION", requestCode)
}
in case you are running background code where activity is not available you have two options:
migrate to target SDK 29 (and use android.permission.ACTIVITY_RECOGNITION in manifest and checks/request) - we tested it and it works
at the start of main activity or any suitable activity run the call above which will ask user for permission
I have app (current targetsdkversion is 23) running in version 4.4 & 5.1 but with 6.0 It requires run time permssion.
This needs some coding changes I prefer to defer for sometime. Is it perfectly okay change the targetsdkversion to 22 instead of 23. Does this allow app to be run in 6.0 without using 'run-time permission'? I read app mayn't properly if user decides to change the permission after installation. Im okay with this limitation for now.
Be careful if you have already published the app with targetSdkVersion of 23, those users who have installed it will not be able to "upgrade" to a new version of your app because of the target SDK downgrade. They'll have to uninstall then re-install your app.
But, to answer your question about API levels, yes it will run fine on Marshmallow with target SDK set to 22. The users will be presented with an old style permission accept dialog when installing the app and all permissions will be granted at install time. However, users could go in a disable the permissions via Settings so your app could start receiving SecurityException for protected operations.
Simply changing from android:targetSdkVersion="22" to "23" causes my app to crash on the Galaxy S6. What would cause that? Rolling back and everything is fine.
I don't have an S6 so I cannot replicate - I'm sure it is something simple...
The most likely cause is the permissions required by your app, specified in your Manifest.
"Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app."
See Requesting Permissions at Run Time
In particular if your app requires any of the permissions listed in the Dangerous permissions and permission groups table, you will need to implement code to ask for those permissions at runtime on devices running 23 or higher. If you don't, and you try to perform a task that requires one of these permissions, the app will crash.
Normal (Non-dangerous) permissions however, are automatically granted by the system if required, and do not need to be individually requested at run time.
If you want to avoid this issue, just leave your target SDK as 22.
If there are other features of SDK 23 that you particularly need then you will need to go through the steps indicated in the first link above so that permissions are requested at run time on devices running 23 or higher.
Marshmallow (23) has been rolled out for the Galaxy S6 in many regions now. If you can find out what Android version the Galaxy S6 that is experiencing the crash is running, I bet you'll find it's Marshmallow.
I just come to know newer tag in android manifest file called "uses-permission-sdk-23"
<uses-permission-sdk-23 android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.CAMERA" />
Can anybody please provide difference between this two?
Summary
<uses-permission> applies to all SDKs and <uses-permission-sdk-23> will apply the permission only to SDK 23+.
When should you use <uses-permission-sdk-23>?
For Android SDK 23 and above, you have the option to request the permission at runtime but the permissions will be in their default state upon installation and the user will not be prompted at installation. (Essentially this can be used to prompt the user to grant the permission on a need-to-use basis and you have the opportunity to provide an explanation of why it's needed.)
However, for SDK 22 and below, the user is prompted at installation for permissions. As some permissions can seem suspicious or dodgy to the user, you may not want to request these for SDK 22 and below as you can't provide an explaination of why you need them beforehand, hence the <uses-permission-sdk-23> tag.
Additionally: the documentation is unclear as to whether sdk-23 permissions also cause the app to be filtered in the Play Store, but if it was your intention to do this, the documentation recommends that you make use of <uses-feature> elements instead to declare hardware compatability.
Recommendation
Generally, it is considered best practice to use <uses-permission-sdk-23> if your app does not need to support SDK 22 and below, or if the permission you are requesting is not needed for SDK 22 or below as it is then clear that this permission is requested at runtime.
Otherwise, <uses-permission> should be used as this is backwards compatible and the behavior will be correct on any SDK version; 22 and below, permissions will be requested at installation. 23 and above, it's up to you to request at runtime.
You should request permissions at runtime wherever possible as it allows you to explain to your user why you need certain permissions rather than just prompting them with a list of permissions at install time when the user has likely not established trust in the app.
Notes
Both of these accept a maxSdkVersion attribute that can be used when a permission was required for older devices but is not required for newer devices. (For example, the WRITE_EXTERNAL_STORAGE example shown in the Android documentation.)
Reference: (Android Documentation)
if the app is running on a device with SDK version 23 or higher. If the device is running SDK version 22 or lower
when you update an app to include a new feature that requires an additional permission. If a user updates an app on a device that is running SDK version 22 or lower, the system prompts the user at install time to grant all new permissions that are declared in that update. If a new feature is minor enough, you may prefer to disable the feature altogether on those devices, so the user does not have to grant additional permissions to update the app. By using the uses-permission-sdk-23 element instead of uses-permission
you can request the permission only if the app is running on platforms that support the runtime permissions model, in which the user grants permissions to the app while it is running.
for More info refer this.uses - Permission sdk 23
By using the <uses-permission-sdk-23> element instead of <uses-permission>, you can request the permission only if the app is running on platforms that support the runtime permissions model, in which the user grants permissions to the app while it is running.
This has been introduced to support runtime permission feature of Marshmallow (API-23) onwards.
This simply specifies that an app wants a particular permission, but only if the app is running on a device with SDK version 23 or higher. If the device is running SDK version 22 or lower, the app does not have the specified permission.
This element is useful when you update an app to include a new feature that requires an additional permission. If a user updates an app on a device that is running SDK version 22 or lower, the system prompts the user at install time to grant all new permissions that are declared in that update.
You can reffer to the documentation.
user-permission-sdk-23 specifies that the app that wants a particular permission is running on SDK version 23 or higher.
It is used when you update your app to run SDK 23 elements and the users running a lower API which does not support the new elements.
Android manifest - user permissions
Specifies that an app wants a particular permission, but only if the app is running on a device with API level 23 or higher. If the device is running API level 22 or lower, the app does not have the specified permission.
see the documentation
uses permission
Use
<uses-permission-sdk23>
to apply permission for Marshmallow devices only.
My project is a long running project. I had set the target version as 10, 4 years back. I cant change the target version to 23, since I am using httpImageCache and also having issues with UI's. My problem is, when Marshmallow released I tried to integrate Marshmallow with targetVersion 10,
int returnedPermission = ContextCompat.checkSelfPermission(MyActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
this function is always returing '0' if I manually ON or Off storage permission from App Settings page. Can any one please help me?
As #Commonware has already given the answer, but here I am adding more detail to the question which might help you.
As per the official android developer site:
If the device is running Android 5.1 or lower, or your app's target
SDK is 22 or lower: If you list a dangerous permission in your
manifest, the user has to grant the permission when they install the app; if they do not grant the permission, the system does not install the app at all.
If the device is running Android 6.0 or higher, and your app's target
SDK is 23 or higher: The app has to list the permissions in the
manifest, and it must request each dangerous permission it needs
while the app is running. The user can grant or deny each permission,
and the app can continue to run with limited capabilities even if the
user denies a permission request.
As your target SDK is 10, application will run perfectly like previous. Anyway please note that user still can revoke a permission after that..!!! Although Android 6.0 warn the user when they try to do that but they can revoke anyway.
Above statement is taken from official android developer site.
Can any one please help me?
Delete that code, as it is useless for you. If your targetSdkVersion is below 23, you cannot find out whether or not the user revoked permissions.
use PermissionChecker.checkSelfPermission()
when targetSdkVersion <= 22,you also can use requestPermission()