由网友(被泪淋湿的记忆)分享简介:我想启用/禁用(切换)通过一个按钮点击GPS编程方式在我的应用程序,但它不工作。请帮忙。我的目标设备没有根。这里的code我使用。私人无效GPS(){意向意图=新的意图(android.location.GPS_ENABLED_CHANGE);巴顿GPS =(按钮)findViewById(R.id.gpsBu...
我想启用/禁用(切换)通过一个按钮点击GPS编程方式在我的应用程序,但它不工作。请帮忙。 我的目标设备没有根。
这里的code我使用。
私人无效GPS()
{
意向意图=新的意图(android.location.GPS_ENABLED_CHANGE);
巴顿GPS =(按钮)findViewById(R.id.gpsButton);
如果(isGPSon())
{
intent.putExtra(已启用,真正的);
gps.setText(R.string.f2_gps_deact);
}
其他
{
intent.putExtra(已启用,假);
gps.setText(R.string.f2_gps_act);
}
sendBroadcast(意向);
解决方案
您不能启用GPS编程。你可以做的最多的就是打开设置为用户做到这一点。
您可以做到这一点是这样的:
startActivityForResult(新意图(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS),100);
I am trying to enable/disable (toggle) GPS programmatically in my app via a button click, but it is not working. Please help. My target devices are not rooted.
Here's the code I'm using.
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);
解决方案
You can't enable GPS programatically. The most you can do is open the settings for the user to do that.
You can do it like this:
startActivityForResult(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 100);
相关推荐
最新文章