开发者

Android GPS enable programmatically [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

How can I enable or disable the GPS programmatically on Android?

I want to get lati开发者_开发技巧tude and longitude programmatic in Android app. But it depended upon whether the GPS is enabled or not. I used to check the GPS with this code

LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
{
    if(!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER )) 
    { 
        Intent myIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS );
        startActivity(myIntent);
    }
}

But it basically shows the screen to enable it. But I don't want that user should enable it. It should enable automatically if the gps is disabled.


You can't, starting with Android 1.5. The most you can do is pop open the activity to allow the user to toggle it on/off.

Use the action held in android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS to craft an Intent to open this activity.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜