Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enforce the custom permission on an Activity in Android?

Tags:

I have created a custom permission in android as:

<permission     android:name="com.master.me.CUSTOM_PERMISSION_TEST"     android:description="@string/des_permission"     android:label="labelhere"> </permission> 

How will I enforce this in my Activity in AndroidManifest.xml file?

like image 500
Master Avatar asked Feb 11 '14 04:02

Master


People also ask

How do I set custom permissions on Android?

You can use the sharedUserId attribute in the AndroidManifest. xml 's manifest tag of each package to have them assigned the same user ID. By doing this, for purposes of security the two packages are then treated as being the same app, with the same user ID and file permissions.

Which is permission enforcement in Android?

App permissions help support user privacy by protecting access to the following: Restricted data, such as system state and a user's contact information. Restricted actions, such as connecting to a paired device and recording audio.

How can I customize permissions dialog in Android?

The short answer is, you can't. As android documentation puts: When your app calls requestPermissions(), the system shows a standard dialog box to the user.


1 Answers

Use android:permission attribute into activity tag.

Like below

<activity android:permission="com.master.me.CUSTOM_PERMISSION_TEST"             android:name=".YourActivity"             android:label="@string/activity_label" /> 

And you need to add uses-permission to your custom permission, when your other application needs to launch this activity.

<uses-permission android:name="com.master.me.CUSTOM_PERMISSION_TEST"/> 

An In-Depth Introduction to the Android Permission Model is a very good article to understand permission in Android. And How to use custom permissions in Android? is also a very good SO thread.

like image 164
Pankaj Kumar Avatar answered Oct 23 '22 19:10

Pankaj Kumar