简体   繁体   中英

Uses-Permission vs Uses-Feature

I've seen many specific cases of people asking and people explaining the difference between the two but I can't and don't seem to understand the general difference. Are the two synonymous? Does one imply the other?

Are the two synonymous?

No. <uses-permission> says "hey, Android (and associated distribution channels), please ask the user to allow me to do X". <uses-feature> says "hey, Android (and associated distribution channels), I am interested in running on hardware with feature Y".

<uses-feature> may filter you out of the Play Store (and other channels), if the hardware does not meet your requirements, but the user doesn't get involved.

Does one imply the other?

Sometimes. If you request certain permissions, like CAMERA , Android assumes by default that you need the corresponding hardware . You can use <uses-feature> and android:required="false" to override that default behavior, if needed.

It is recommended to use <uses-feature> along with <uses-permission> . Every feature of your app needs <uses-feature> with attribute android:required="false" if your app can work without it . The reason for this is that Google Play filters out applications which have features implemented programmatically but not supported by hardware, and as a result you don't see them there.

For example, among other several permissions your app has a permission <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> . If there is a device which doesn't have GPS capability, then this device will not see this app in Google Play. If your app completely functional without a GPS Connection, then the solution would be to add:

<uses-feature android:name="android.hardware.location" android:required="false"/> 
<uses-feature android:name="android.hardware.location.gps" android:required="false"/>
<uses-feature android:name="android.hardware.location.network" android:required="false"/>

Thus, as it is already mentioned by @CommonsWare, <uses-feature> overrides the default behaviour of <uses-permission>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM