Android GPS以编程方式启用 [英] Android GPS enable programmatically

查看:87
本文介绍了Android GPS以编程方式启用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
如何在Android上以编程方式启用或禁用GPS?

我想在Android应用中以编程方式获得经纬度.但这取决于是否启用GPS.我曾经用此代码检查GPS

I want to get latitude 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);
    }
}

但是它基本上显示了启用它的屏幕.但我不希望该用户启用它.如果禁用了gps,则应自动启用.

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.

推荐答案

从Android 1.5开始,您不能这样做.您最多可以做的是弹出活动以允许用户打开/关闭活动.

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.

使用android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS中持有的操作来制作打开此活动的意图.

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

这篇关于Android GPS以编程方式启用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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