uses-permission vs permission for android permissions in the manifest.xml file-ThrowExceptions

Exception or error:

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
How to solve:

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.

Leave a Reply

Your email address will not be published. Required fields are marked *