63

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
N J
  • 27,217
  • 13
  • 76
  • 96
Kevik
  • 9,181
  • 19
  • 92
  • 148
  • 1
    Possible duplicate of [Diffrences between Uses-Permission and Permissions tag in AndroidManifest.xml](http://stackoverflow.com/questions/3850799/diffrences-between-uses-permission-and-permissions-tag-in-androidmanifest-xml) – Pankaj Apr 02 '16 at 16:22

4 Answers4

71

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.

A--C
  • 36,351
  • 10
  • 106
  • 92
32

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

Omar Faroque Anik
  • 2,531
  • 1
  • 29
  • 42
  • I'm not sure if its true, but can't they be diferentiated as permission granted at install time (once), vs permission granted at runtime (everytime it's needed)? – Dane411 Feb 10 '15 at 04:14
5

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.

Teng-pao Yu
  • 1,313
  • 15
  • 30
  • The documentation is already quoted/linked in other answers given to this question already. This answer does not add anything new to what is already been given. – SteveFerg Jul 02 '15 at 03:59
  • Hi SteveFerg all three answers are quoting older documents. That's why I'm updating it here. Please re-check the doceuments quoted and let me know if I were wrong. – Teng-pao Yu Jul 02 '15 at 06:50
  • To be specific, the documents they have quoted are not specifically for the problem stated by the question asker, while mine is completedly focused on permissions in Android – Teng-pao Yu Jul 02 '15 at 07:05
  • You are correct in showing a different page, however the third answer (currently with a plus 6) quotes verbatim from the **Declaring and Enforcing Permissions** from your link, is why I said as much. – SteveFerg Jul 02 '15 at 07:31
  • I hate that example above, because it says nothing about how it relates to the already existing `permissionGroup`s and their *individual permissions*. @Henry_Yu Can you please provide a working example? (Not to mention the differences between AOS 5.1 and AOS 6.0 etc. – not2qubit Dec 02 '16 at 09:27
0

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.

iammrmehul
  • 730
  • 1
  • 14
  • 35