Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
240 views
in Technique[技术] by (71.8m points)

android - GPS Manifest: GPS in App is optional, want to make it available to GPS less devices too

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 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 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" />

Edit: thanks for the Answer Raghav Sood!

Add to Manifest:

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

Implement the following:

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

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" />

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Add the following to your manifest

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

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...