GPS 清单:App 中的 GPS 是可选的,也希望它可用于没有 GPS 的设备 [英] GPS Manifest: GPS in App is optional, want to make it available to GPS less devices too

查看:32
本文介绍了GPS 清单:App 中的 GPS 是可选的,也希望它可用于没有 GPS 的设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天在将我的应用程序上传到市场时,我发现它仅适用于具有 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.

这篇关于GPS 清单:App 中的 GPS 是可选的,也希望它可用于没有 GPS 的设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆