Precautions for Android application permission

Apply for permission for Android programs note

Android system provider provides permission application, that is, use uses permission in manifest to apply The implementation is very simple, but some problems will surface A common phenomenon is that sometimes when a new permission is added, the supported devices displayed by the program (on Google play) will be reduced

Why does the more permissions, the less devices supported

Because some permissions implicitly require features, that is, when you display the use permission, the uses feature will be added to the program by default The basis for Android and Google play to judge whether they can be installed and realistic is whether the system features contained in the device fully include all the features applied by the program It can only be displayed and installed on devices that meet all the features required by the program

How to view which features are used by the program

Using AAPT dump bagging your_ apk_ file_ Path. For details, refer to obtaining the features required by the program

How to view the features of a device

Android provides this API. For details, refer to the features supported by the system

for instance

We add a line to the program manifest to apply for the permission of the camera

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

Then view the features added by the program

14:29 $ aapt dump badging PermissionDemo. apk | grep uses-feature

We will find that these two permissions are new

uses-feature:'android. hardware. camera' uses-feature:'android. hardware. camera. autofocus'

Solve the problem: how to add permissions without reducing support devices

If you add permissions and the imported feature is not required, you can set the feature as unnecessary Continue with the example above Add in manifest

<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/> <uses-feature android:name="android.hardware.camera" android:required="false"/>

Regenerate the program Review the required permissions again

14:29 $ aapt dump badging PermissionDemo. apk | grep uses-feature uses-feature-not-required:'android. hardware. camera. autofocus' uses-feature-not-required:'android. hardware. camera' uses-feature:'android. hardware. touchscreen'

In this way, you can increase permissions and ensure that the supporting devices are not reduced

Show Me The Code

Extended reading

http://developer.android.com/guide/topics/manifest/uses-feature-element.html#permissions

The above is the data sorting of Android application permission. We will continue to supplement relevant data in the future. Thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>