Is it possible to avoid runtime permission with admin permission?
I have to change something in Settings.System, but unfortunately on Android M, I have to ask user to allow me...
Permission of WRITE_SETTINGS has been revoked from user apps (as in not system apps) in api23. From looking into source code in android we can see the following protection levels for this permission:
<permission android:name="android.permission.WRITE_SETTINGS"
android:label="#string/permlab_writeSettings"
android:description="#string/permdesc_writeSettings"
android:protectionLevel="signature|preinstalled|appop|pre23" />
which means you can gain this permission by either:
1.Targetting sdk lower then 23 in your manifest
2. By having system signature, by having app preinstalled in system (/app or /priv-app) or by gaining permission through appop (not relevant).
So, as user app targeting sdk23 you cannot gain this permission. Target sdk 22 and lower for gaining this permission from manifest. it works fine.
Related
My Target Api is 30.
I have declared below permissions in my manifest, following this code-lab example(https://developer.android.com/codelabs/activity-recognition-transition#2):
<uses-permission android:name="android.gms.permission.ACTIVITY_RECOGNITION"/>
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>
With this,
1] when my app is running on Android 10 and above, I am able to ask for a ACTIVITY_RECOGNITION permission and it also returns true if I check in my code, like:
ContextCompat.checkSelfPermission(
requireContext(),
Manifest.permission.ACTIVITY_RECOGNITION
) == PackageManager.PERMISSION_GRANTED
2] But the same code always returns false, when my app is running on phone with Android 8(below 10) and I also don't see physical activity under permissions list in App settings.
Questions:
Since I am targeting Android API 30, should I not use > "android.gms.permission.ACTIVITY_RECOGNITION" in manifest? If yes,then will it grant permission when my app runs on phone with Android 8?
Here is what the Android documentation says for ACTIVITY_RECOGNITION permission.
If your app targets Android 9 (API level 28) or lower, the system auto-grants the android.permission.ACTIVITY_RECOGNITION permission to your app, as needed, if your app satisfies each of the following conditions:
The manifest file includes the com.google.android.gms.permission.ACTIVITY_RECOGNITION permission.
The manifest file doesn't include the android.permission.ACTIVITY_RECOGNITION permission.
If the system-auto grants the android.permission.ACTIVITY_RECOGNITION permission, your app retains the permission after you update your app to target Android 10. However, the user can revoke this permission at any time in system settings.*
Basically don't ask for this permission below Android 10 at runtime, just add it in manifest
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I want to add the permissions to access the files and location of user in my android app. Right now when the user open my app, it asks for permissions but if the user deny it my app doesn't work fine due to the downloaded images in his phone. It gives bad impact. Now i want to ask that how i can ask for permission in my app within playstore before downloading my app(Like ES File Explorer File Manager). If the user deny this he can't able to install my app.
From the source: https://developer.android.com/training/permissions/requesting.html
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.
So, i think you can set your target SDK and target API below 22 for using old permission system.
You can do it by selecting API22 as target SDK
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.
BUT ALSO
Note: 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. You should test your app to verify that it behaves properly when it's missing a needed permission, regardless of what API level your app targets.
You have to add some usage permissions in AndroidManifest.xml.
Something like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
//for file access
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
//for location access and updates
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES" />
</manifest>
after adding these permissions you have to create a new release build and post to play store.
Note: these permissions are working fine for API level below 23 but for API 23 or higher you have to check run-time permissions(marshmallow and nougat), for more info about Requesting Permissions at Run Time please go through this link-https://developer.android.com/training/permissions/requesting.html
Hi i am trying to get SYSTEM_ALERT_WINDOW permission i have added <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> in my manifest file. Now when i install the release build, it asks for permission and everything works as expected in marshmallow. But when i install it from playstore it automatically grants me SYSTEM_ALERT_WINDOW permission, but when i try to start a System overlay service, it is giving me error.
W/ActivityManager: Appop Denial: Accessing service ComponentInfo{packagename/packagename.classname} from pid=6189, uid=10289 requires appop SYSTEM_ALERT_WINDOW
But when i checked facebook chathead it was working without asking me permissions.
How do i check for appop denial permissions?
It may not be asking for the permissions if already allowed please check as below:
No permissions have been granted if you go to Settings > Apps > "Your app" > Permissions.
You should uninstall clear app data and uninstall it completely, then install via playstore.
If you don't want to do implement the new system yet then you can reduce your target sdk version to 22 to get the old permission system. You can still compile with sdk version 23 though.
Thanks
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.
Based on google docs beginning with Android 4.4 (API level 19) Android apps doesn't need WRITE_EXTERNAL_STORAGE Permission to write to its own application-specific directories.
uses-permission
So I removed this permission for API 19:
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
But after publishing app, we find out some android devices(not all of them) with API > 18 have problem and app can't write to it's own application-specific directories.
I remove android:maxSdkVersion and published app again and problem solved.
How is that possible?
And what I should do to remove this permission and my app work in all devices?
check following link hope you will find your ans
Require permission only for older android versions: maxSdkVersion does not work?