我有这些:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" android:required="false" />
我可以自己检查 GPS:
locationManager = (LocationManager)
context.getSystemService(Context.LOCATION_SERVICE);
fSupportsGPS = (locationManager.getAllProviders().
contains(LocationManager.GPS_PROVIDER));
但我还是有些疑惑。我希望我的应用程序在没有可用 wifi/gps/网络的设备上运行。我唯一使用 GPS 的原因是在 Google map 上显示用户位置。 (与应用程序的其余部分相比,这是一个微小的功能,所以我不想对它有任何要求。)
最佳答案
<uses-feature ...>
告诉 Android 该应用程序必须需要该功能,没有它就无法运行,因此 Android 不允许用户安装该应用程序(事实上,它甚至不会出现在 Play 中商店/市场。
要让没有这些功能的用户安装您的应用,您只需添加 android:required="false"
相应功能的选项。您已经使用此 XML 在 list 中完成了:
<uses-feature android:name="android.hardware.camera" android:required="false"/>
要检测用户是否拥有该功能(因为现在他们拥有它不是强制性的),您可以使用 Android API。您已经使用此 Java 代码完成了此操作:
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
fSupportsGPS = (locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER));
现在,您不能做的一件事是让使用 Android 1.6 和更早版本且没有这些功能的用户安装应用程序,即使这些功能被标记为可选。这是因为 Android 版本无法识别 android:required
this answer 中解释的功能.
要记住的另一件事是一些 <uses-permission ...>
标签会触发一些隐含的权限要求。
为了解决这个问题,引用自docs :
If you don't want Google Play to filter based on a specific implied feature, you can disable that behavior. To do so, declare the feature explicitly in a element and include an android:required="false" attribute. For example, to disable filtering derived from the CAMERA permission, you would declare the feature as shown below.
<uses-feature android:name="android.hardware.camera" android:required="false" />
根据 this page , <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
暗示网络的要求。要禁用它,请将其添加到您的 list 中:
<uses-feature android:name="android.hardware.location.network" android:required="false" />
关于android - 使 Android "uses-permission"可选,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15430272/