当前位置:操作系统 > 安卓/Android >>

android 代码 操作 gps 开关

在研究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();

                 }

    }


摘自 chenghai2011的专栏
补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,