我试图找到一些code,这将帮我看看,我用该设备具有GPS或不?我不想知道GPS是启用或禁用。我只是想知道,如果该设备具有GPS硬件或不通过我的程序。
I am trying to find some code which will help me to find out if the device which I use has GPS or not? I don't want to know if GPS is enabled or disabled. I just want to know if the device has GPS hardware or not through my program.
是的,这是可以做到。
您可以拨打LocationManager.getAllProviders()并检查是否 LocationManager.GPS_PROVIDER
包含在列表中。
You can call LocationManager.getAllProviders()
and check whether LocationManager.GPS_PROVIDER
is included in the list.
仅供参考,我相信所有已发布的Android手机都配备了GPS。这不是说Android的似乎是担心,例如:提GPS作为由PackageManager.getSystemAvailableFeatures().
Just for reference, I believe all released Android phones come with a GPS. It's not something that Android seem to be worrying about, e.g. mentioning GPS as one of the device attributes returned by PackageManager.getSystemAvailableFeatures()
.