在研究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的專欄