您的位置:首页 > 移动开发 > Android开发

android 代码 操作 gps 开关

2011-12-06 21:45 211 查看
在研究android gps 的时候,发现android系统隐藏了对gps开关操作的接口,也不知道为什么,个人觉得可能是怕所有的程序都区操作gps 开关从而导致混乱吧!但是还是在网上看到了一个用代码对gps 开关进行操作的方法。 贡献出来!

====================================================================================

直接上代码:

private voidtoggleGPS() {

IntentgpsIntent = newIntent();

gpsIntent.setClassName("com.android.settings",

"com.android.settings.widget.SettingsAppWidgetProvider");

gpsIntent.addCategory("android.intent.category.ALTERNATIVE");

gpsIntent.setData(Uri.parse("custom:3"));

try {

PendingIntent.getBroadcast(this, 0,gpsIntent, 0).send();

}

catch (CanceledExceptione) {

e.printStackTrace();

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: