I'm using WRITE_EXTERNAL_STORAGE runtime permission. However, the app seems to be working fine even when I didn't mention <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> in my manifest file.
Question: What are the implications of adding / not adding runtime permissions in manifest and the common best practices around permissions.
What you're probably experiencing is that the WRITE_EXTERNAL_STORAGE permission is all but deprecated starting with Android 10. This is part of Google's Scoped Storage enforcement:
https://developer.android.com/preview/privacy/storage
You're supposed to declare runtime permissions in AndroidManifest. Try the same thing with another dangerous permission and see if it acts the same way.
Beginning with Android 4.4 (API 19), there is no need to request WRITE_EXTERNAL_STORAGE permission when your app wants to write its own application-specific directories on external storage(provided by getExternalFilesDir() method). However, to make your app compatible with levels <= 18, you will need the uses-permission tag.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" />
Related
In the android manifest, there are sometimes permissions named as:
com.google.android.gms.permission...
or android.permission....
Is this naming arbitrary or is there a reason for having different prefixes?
The reason I would like to know this is to be able to locate the right permissions I usually go to the https://developer.android.com/reference/android/Manifest.permission
This link contains only ones with "android.permission.*" I would like to know if there is a single reference somewhere for all the other permissions?
P.S. Below is an example of ACTIVITY_RECOGNITION being added to the manifest, trying to make sense of it.
<!-- Required for 28 and below. -->
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
<!-- Required for 29+. -->
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
Is this naming arbitrary or is there a reason for having different prefixes?
android.permission is used for permissions in the Android Open Source Project.
com.google.android.gms.permission is used for permissions from what we think of as Play Services.
Other apps can define their own permissions, ideally in their own namespaces. But, they are just strings, so you or I could try defining a custom permission that starts with android.permission.
I would like to know if there is a single reference somewhere for all the other permissions?
Permissions are arbitrary strings from arbitrary developers. There is no way to know what all of them are. I am not aware of Google having documentation listing all of Play Services' permissions, but I cannot rule it out.
Below is an example of ACTIVITY_RECOGNITION being added to the manifest, trying to make sense of it.
This was tied to functionality that originally was supplied by Play Services and then moved into Android itself. So, the permission started with the Play Services namespace and then was cloned into the AOSP namespace.
I have a Cleaner app in java that has features like - System cleaner, Whatsapp manager, and Basic file Explorer to list & delete files i.e. downloads, images, videos, documents and audio.
Now it has to comply with Google's scoped storage enforcement or it will be removed from the store.
My question here is:
How to I make sure I am using correct permissions to comply with this policy? While making sure the older versions of Android would
still work as normally (or scoped storage api works with them too?).
What I have already done:
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
I have updated the permissions as shown above^ and set target sdk to 30, as well as removed requestLegacyExternalStorage flag from
manifest file.
Notice that WRITE_EXTERNAL_STORAGE is using max sdk = 28 tag, do I need to do this with other two (READ&WRITE) permissions also? (official doc only showed example of write-external-storage permission)
I'm still asking for these permissions in java code - do I need to wrap that code using if (Build.VERSION.SDK_INT < 30) to make sure
it's only asked in lower android versions or using the above tag in
manifest already takes care of that for me?
I have already implemented the requestDeletePermission() dialog for deleting files in Android 11 - it works! But for listing files in Basic explorer I'm
still using the old code that worked in old Android versions - do I
need to update that too? (Although it's still working with above 3 permissions)
Please help me I really have to finish it before the end of this month or my app will get removed. The whole point is to avoid violating the new policy in Android 11. I'm willing to give higher bounty to elaborative answers.
Thank you.
I've mentioned the following permission:
<uses-permission android:name="android.permission.NFC" />
in my manifest.xml. But NFC code is no more in use and I commented the source code. Means NFC is no more in use for my app, but while installing the app, it's still shows in installing window.
So, is it possible in android that don't ask for permissions mentioned in Manifest.xml file, if code is not in use? Thanks
No, it is not possible, because the Android system has no idea which permissions your application requires before run-time. Picture the following scenario:
You are writing an application, not specifying NFC permission as you're not using it in your code, but you ARE using a framework that in 50% of the implementations do use NFC (device manufacturer specific framework).
The Android system has no way of telling if the NFC permission is required and thus it relies on your explicit instruction for permissions
As I'm sure you've noticed, an exception will be raised if the permission does not exist for the specified action
The only way to make sure the requirement is gone is to remove the permission from the manifest (and frankly, is it that much of a deal?)
Besides commenting out the unnecessary codes, you have to remove the permission from your manifest as well.
android.permission.RECORD_AUDIO
I'm not using this permission in my manifest file and I even searched in my whole project and didn't find it. But still when I try to install my app, it asks for this permission and if I click on it, it gives me msg
Microphone
provided by Android System
android.permission.RECORD_AUDIO
I want it to be removed as I don't want to use it! Any idea how to remove it?
One of library accessing microphone in script and I think unity adds permission based on that by it self.
if you dont know who is adding it you can remove it in the final manifest by using xmlns tool like below
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="auto">
...
<uses-permission android:name="android.permission.RECORD_AUDIO" tools:node="remove" />
...
ofcourse just be careful and make sure no code really require it since you might crash if code or one of your plugins enters a point where it requires this permission to run
Yesterday I released my app and realised that it is not available for my android 2.3.3 device. (Does not get listet in search results, and when I access the app page directly, android market tells me that it is not available for my device).
The lines of my manifest, which could be the issue (IMO) look like that:
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-feature android:name="android.hardware.camera.autofocus" />
The only thing I can think of which could make a difference is that I have no SIM card inserted on that phone- but I have Wifi access. (will try it with SIM card in the evening)
Any ideas?
Application requires autofocus camera unless you add `android:required="false" to the use-feature tag.
From documentation, see last if statement:
Filtering based on explicitly declared features
An explicitly declared feature is one that your application declares in a element. The feature declaration can include an android:required=["true" | "false"] attribute (if you are compiling against API level 5 or higher), which lets you specify whether the application absolutely requires the feature and cannot function properly without it ("true"), or whether the application prefers to use the feature if available, but is designed to run without it ("false").
Android Market handles explicitly declared features in this way:
If a feature is explicitly declared as being required, Android Market adds the feature to the list of required features for the application. It then filters the application from users on devices that do not provide that feature. For example:
<uses-feature android:name="android.hardware.camera" android:required="true" />
If a feature is explicitly declared as not being required, Android Market does not add the feature to the list of required features. For that reason, an explicitly declared non-required feature is never considered when filtering the application. Even if the device does not provide the declared feature, Android Market will still consider the application compatible with the device and will show it to the user, unless other filtering rules apply. For example:
<uses-feature android:name="android.hardware.camera" android:required="false" />
If a feature is explicitly declared, but without an android:required attribute, Android Market assumes that the feature is required and sets up filtering on it.
The minSdkVersion="7" and targetSdkVersion="8" but you device is 2.3.3 which equal sdk version 10
This will help you to know the sdk versions
so change the versions range in your manafist file
<uses-sdk android:targetSdkVersion="8" android:minSdkVersion="7" android:maxSdkVersion="10" />