I have a few questions regarding how 'custom' permissions work in Android 6.0 with the new runtime permissions. For instance, a declared custom permission like this.
<permission android:description="com.mycompany.myapp.DEADLY_ACTIVITY"
android:label="string resource"
android:name="string"
android:protectionLevel="dangerous" />
I could not find any information online that specify how to handle this type of custom permissions at runtime in Android M.
Should I handle and check "com.mycompany.myapp.DEADLY_ACTIVITY" permission in methods at runtime the same way I check dangerous android perimissions(camera, calendar etc.) with checkSelfPermission()? and provide rationale per Google's new standards?
Many Thanks!
Yes. You can check the permission with the ContextCompat.checkSelfPermission method using the permission name you declared in the manifest.
So if you declared this in the manifest:
<permission android:description="com.mycompany.myapp.DEADLY_ACTIVITY"
android:label="string resource"
android:name="com.mycompany.myapp.permissionName"
android:protectionLevel="dangerous" />
then you can check the permission anywhere in the app with this:
if(ContextCompat.checkSelfPermission(context, "com.mycompany.myapp.permissionName") == PackageManager.PERMISSION_GRANTED
Related
I started targeting Android 13 with API 33. The app is requesting Manifest.permission.READ_EXTERNAL_STORAGE for the older APIs. Now I know that I have to request the new permissions: READ_MEDIA_IMAGES and READ_MEDIA_VIDEO.
I have added in the manifest:
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
and now, as a result, in the setting of the permissions for the app I see an extra option to enable these permissions.
What I can't do is to ask the permission at runtime
If I try to access Manifest.permission.READ_MEDIA_IMAGES in the code I get unresolved reference so I can't dynamically request the permission and if I don't then the user needs to do it manually.
How to handle the READ_MEDIA_IMAGES and READ_MEDIA_VIDEO?
According to official documentation https://developer.android.com/about/versions/13/behavior-changes-13#granular-media-permissions, you should ask permission in runtime.
Also notice:
Note: If your app only needs to access images, photos, and videos, consider using the photo picker instead of declaring the READ_MEDIA_IMAGES and READ_MEDIA_VIDEO permissions.
In my Application I'm using expo-image-picker to pick image to update the user's profile picture.
I had done the implementation. while implementing I used CAMERA_ROLL as type to check the permissions for Gallery.
By Default Expo is includes all permissions link. I don't need that. I need to use only CAMER_ROLL as permission. I went through the app.json configuration docs but there, I can't find CAMER_ROLL or GALLERY related permissions.
What permission to be added in app.json for CAMERA_ROLL ?
You need to add these permissions to your AndroidManifest.xml file.
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
I also had similar scenario. CAMERA_ROLL permission is all about reading and writing to the storage memory. So, it requires below Android permission needs to be added in app.json
READ_EXTERNAL_STORAGE
WRITE_EXTERNAL_STORAGE
According to the Android documentation (https://developer.android.com/reference/android/provider/ContactsContract.Profile.html), I need to request the android.permission.READ_PROFILE permission to read the user's profile information.
However, when I attempt to create runtime permission request, there is no Manifest.permission.READ_PROFILE I can use. Do I just use the Manifest.permission.READ_CONTACTS permission instead?
Note: The AndroidManifest.xml file can find the permission just fine:
<uses-permission android:name="android.permission.READ_PROFILE" />
READ_PROFILE permission was removed on API 23 as you can see here
https://developer.android.com/sdk/api_diff/23/changes.html
You should ask for GET_ACCOUNTS, or any of the permissions belonging to the CONTACTS group
https://developer.android.com/guide/topics/permissions/requesting.html#perm-groups
When I start to install myapp.apk, I get the below screen.
My app requires Location, External Storage permission. Above permissions are supposed to be requested from user as required i.e. just before the code which required these permissions.
Now , when app is installed I get a screen which say App doesn't require any special access as in the screen below. Why?
This is my permission code in Manifest file.
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.previders.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<uses-permission android:name="android.permission.ACCESS_DOWNLOAD_MANAGER" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
With Android 6.0, was introduced the new Android permissions runtime control. Shortly: on older devices all permissions were provided on install of app, from Android M needed permission is used only on runtime, when it is really needed, like Camera activity.
Are you overwriting app? This scenario happens when you already have app installed and installing same app or same app with new version.
If you don't have any new permission added in new app then it will show like that.
As Jadav Lalit already said:
if you install an app it will ask for the permissions it needs. This is also the case for installing, uninstalling and re-installing an app.
if you reinstall or install a newer version of the app without new permissions, it will not ask for any permissions.
On a side note, if you only need Location and External Storage permission you should only have ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION, READ_EXTERNAL_STORAGE and maybe WRITE_EXTERNAL_STORAGE.
You could also add ACCESS_LOCATION_EXTRA_COMMANDS since you use location.
Anyhow a complete list is here: https://developer.android.com/reference/android/Manifest.permission.html
They are all there and up to date, but the description can be a little short sometimes.
A more descriptive list is here: http://androidpermissions.com/ but seems a little out of date updated.
I noticed that there are two types of permissions in the manifest file, "permission" and "uses-permission" like the two shown below;
<permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
for the following 4 permissions which do I use when I put them in my manifest.xml file? uses-permissions or permissions?
android.permission.ACCESS_NETWORK_STATE
android.permission.ACCESS_WIFI_STATE
android.permission.INTERNET
android.permission.CHANGE_WIFI_MULTICAST_STATE
For
<permission>
The documentation states:
Declares a security permission that can be used to limit access to specific components or features of this or other applications.
Therefore, since you are accessing Android's permissions, you want uses-permission instead. The documentation for this element states:
Requests a permission that the application must be granted in order
for it to operate correctly.
<permission> is normally used when making a custom permission (e.g. when making an app that other apps can tie in to, limiting access is a must), and <uses-permission> is used when your app actually needs a permission it doesn't have normally.
Lets start with "uses-permission...": Suppose you want to use GoogleMap in your application as an example to find a nearest location of any office such as bank or any other office. You need internet. So you need to give the permission to your android device to access INTERNET. This is done by using android permission called .
<uses-permission android:name="android.permission.INTERNET" />
Now come to "permission..": what it does is it Declares a security permission that can be used to limit access to specific components or features of this or other applications.If your application need some resources or some feature from other application, you can use by giving the specific class or package.
<permission android:name="com.example.project.DEBIT_ACCT" . . . />
Thanks. for more information, you can read
http://developer.android.com/guide/topics/manifest/manifest-intro.html
In short, the one you needed is the uses-permission statement.
Androird Document now has a dedicated page discussing these two usages.
In the Using Permissions part, it explains that
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.app.myapp" >
<uses-permission android:name="android.permission.RECEIVE_SMS" />
...
</manifest>
is used to declare what permissions you'd like to use.
While in Defining and Enforcing Permissions you can see that
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.me.app.myapp" >
<permission android:name="com.me.app.myapp.permission.DEADLY_ACTIVITY"
android:label="#string/permlab_deadlyActivity"
android:description="#string/permdesc_deadlyActivity"
android:permissionGroup="android.permission-group.COST_MONEY"
android:protectionLevel="dangerous" />
...
</manifest>
is used to define your own permission.
In layman terms, <uses-permission> specifies permissions your app needs to access some component restrict by another app that is the owner of that component.
<permission> specifies the restrictions you are placing on your components are the component owner.