我想在程序中通过点击一个按钮,以程序的方式来实现启动或禁用GPS,但是不能实现。
我要用的设备没有设置权限。
这是我使用的代码,错误出自哪呢?
private void gps()
{
Intent intent=new Intent("android.location.GPS_ENABLED_CHANGE");
Button gps = (Button)findViewById(R.id.gpsButton);
if(isGPSon())
{
intent.putExtra("enabled", true);
gps.setText(R.string.f2_gps_deact);
}
else
{
intent.putExtra("enabled", false);
gps.setText(R.string.f2_gps_act);
}
sendBroadcast(intent);
你不能以编程的方式启动GPS。你能做的就是给用户打开设置。
你可以添加:
startActivityForResult(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 100);