9

What is the difference between these two syntaxes. android:uses-permission and uses-permission. For example:

<android:uses-permission
  android:name="android.permission.READ_EXTERNAL_STORAGE"
  android:maxSdkVersion="18" />

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

The first one was automatically added to the manifest by Android Studio when I created an activity that reads from storage. Also why did it add an android:maxSdkVersion attribute and specifically set it to 18 when I have targetSdkVersion for the project set as 21.

MiJo
  • 569
  • 5
  • 19
  • The answer to this depends on the namespace declarations in your XML manifest file. Please post your complete file. – Greg Hewgill Feb 26 '15 at 19:47
  • 1
    "The first one was automatically added to the manifest by Android Studio when I created an activity that reads from storage" -- ummm, really? What specifically did you do in the IDE that triggered it to add this to your manifest? AFAIK, `android:uses-permission` is a bug, and it certainly is not how it normally appears. The `android:maxSdkVersion` is because if you are only working with `getExternalFilesDir()` and `getExternalCacheDir()`, you do not need that permission on Android 4.4+ devices. If you plan on working with other external storage locations, remove `maxSdkVersion` from the tag. – CommonsWare Feb 26 '15 at 19:50
  • I'm not sure how you got those two permissions but The 1st android:uses-permission means beginning with API level 19, the system will no longer grant your app the READ_EXTERNAL_STORAGE permission. for more details : http://developer.android.com/guide/topics/manifest/uses-permission-element.html – Mounir Elfassi Feb 26 '15 at 19:57
  • @CommonsWare that makes sense. It was automatically added when I created an activity that reads an Image from storage and ran debug. I am using Android Studio 1.1.0. – MiJo Feb 26 '15 at 20:03
  • @MounirElfassi the second one was added by me because the app kept crashing complaining not having permissions. – MiJo Feb 26 '15 at 20:03
  • Refers this link. http://stackoverflow.com/questions/14450839/uses-permission-vs-permission-for-android-permissions-in-the-manifest-xml-file – Bhavin Shah Feb 28 '15 at 11:38

1 Answers1

-1
<uses-permission
     android:name="android.permission.WRITE_EXTERNAL_STORAGE"
     android:maxSdkVersion="18" />

Actually this permission is required for API level 18 and lower, Android 4.4 (API level 19), it's no longer necessary for your app to request the WRITE_EXTERNAL_STORAGE permission when your app wants to write to its own application-specific directories on external storage (the directories provided by getExternalFilesDir().

Anggrayudi H
  • 14,977
  • 11
  • 54
  • 87
dhimanta
  • 219
  • 3
  • 11
  • this case is not seen when we used eclipse. nothing is discussed about it in this link http://developer.android.com/guide/topics/manifest/uses-permission-element.html – Amrut Bidri Mar 04 '15 at 11:21