[英]Android this app turns GPS on and off
我最近在Google Play上看到了此應用
https://play.google.com/store/apps/details?id=com.androidlost&hl=fr
我特別想知道它是如何做這種事情的? (請注意,出於安全原因,您通常無法使用Android SDK來做到這一點...)
* start/stop GPS
* start/stop WIFI
有什么技巧可以做到這一點?
謝謝
對於啟用/禁用GPS編程看到這個和無線上網:
String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
final Intent poke = new Intent();
poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
poke.setData(Uri.parse("0"));
int wifistatus = ((WifiManager)con.getSystemService(Context.WIFI_SERVICE)).getWifiState();
if(wifistatus==1) //if WIFI is disabled
{
sendBroadcast(poke);
}
else //if WIFI is enable
{
sendBroadcast(poke);
}
manifest.xml權限:
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.