GPS 清单:App 中的 GPS 是可选的,也希望它可用于没有 GPS 的设备可选、清单、可用于、设备

2023-09-07 04:10:12 作者:凉夜旧街深港少年与蓝海i

今天在将我的应用程序上传到市场时,我发现它仅适用于具有 GPS 的设备,因此不包括某些平板电脑.

On uploading my App onto the market today, I saw that it is only available to devices with GPS, so this excludes some tablets.

我的应用程序中的 GPS 是可选的.是否可以为有和没有 GPS 的设备发布一个应用程序,或者我需要制作一个额外的版本(不过没问题)?

GPS in my App is optional. Is it possible to release one App for devices with and without GPS or do I need to make an extra version (would be no problem, though)?

如果可能的话,我想有某种方法可以检查 if(deviceHasGPS()){...}.有吗?

If it is possible, I guess there is some sort of method to check if(deviceHasGPS()){...}. Is there one ?

这是我的清单的一部分:

This is the part of my manifest:

<uses-permission android:name="android.permission.PREVENT_POWER_KEY" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="com.android.vending.CHECK_LICENSE" />

感谢您的回答Raghav Sood!

添加到清单:

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

执行以下操作:

locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
boolean deviceHasGPS = false;
    if (locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER)) {
        deviceHasGPS = true;
    }

要在带有 gps 的设备上测试它,只需用 if(deviceHasGPS){...} 包围 gps 的东西然后在清单中删除:

to test it on a device with gps, just surround the gps things with if(deviceHasGPS){...} then remove in the manifest:

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

将 deviceHasGPS 设置为始终为 false 并查看 App force 是否关闭.

set deviceHasGPS to always false and see if the App force closes.

推荐答案

将以下内容添加到您的清单中

Add the following to your manifest

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

这将告诉 Google Play,虽然您的应用具有 GPS,但绝对要求并非如此.但是,您应该优雅地处理应用中缺少 GPS 的问题,而不是让它崩溃.

This will tell Google Play that while your app has the GPS, it's absolute requirement isn't true. However, you should handle the lack of GPS in your app gracefully, instead of letting it crash.

要检查设备是否有 GPS,您可以调用 LocationManager.getAllProviders() 并检查 LocationManager.GPS_PROVIDER 是否包含在列表中.

To check is the device has GPS you can call LocationManager.getAllProviders() and check whether LocationManager.GPS_PROVIDER is included in the list.