简体   繁体   English

Android这个应用程式可开启和关闭GPS

[英]Android this app turns GPS on and off

I recently saw this app on the Google Play 我最近在Google Play上看到了此应用

https://play.google.com/store/apps/details?id=com.androidlost&hl=fr https://play.google.com/store/apps/details?id=com.androidlost&hl=fr

I was particularly interested to know how does it do that kind of stuff ?? 我特别想知道它是如何做这种事情的? (knowing that for security reasons you can't do it with the Android SDK normally...) (请注意,出于安全原因,您通常无法使用Android SDK来做到这一点...)

* start/stop GPS
* start/stop WIFI

Is there any kind of trick to allow this to be possible ? 有什么技巧可以做到这一点?

Thank you 谢谢

for Enable/Disable GPS programatically see this and for 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 permission : 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM