[英]android programmatically Turning on and off GPS in android 4.0 and up
我想在一個活動中打開和關閉gps本地化,嘗試其他所有主題,這不起作用。 這不是重復的主題,我看起來都是其他主題 。
例:
表現:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.Manifest.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.Manifest.permission.ACCESS_COARSE_LOCATION" />
活動:
public void turnGPSOn()
{
Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", true);
this.ctx.sendBroadcast(intent);
String provider = Settings.Secure.getString(activityname.this.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if(!provider.contains("gps")){ //if gps is disabled
final Intent poke = new Intent();
poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
poke.setData(Uri.parse("3"));
activityname.this.sendBroadcast(poke);
}
}
// automatic turn off the gps
public void turnGPSOff()
{
String provider = Settings.Secure.getString(activityname.this.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if(provider.contains("gps")){ //if gps is enabled
final Intent poke = new Intent();
poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
poke.setData(Uri.parse("3"));
activityname.this.sendBroadcast(poke);
}
}
當我嘗試我的應用程序停止(崩潰)時
來源: 在Android 4.0及更高版本中以編程方式打開和關閉GPS?
我不希望顯示對話框(選擇打開本地化)我需要以編程方式進行所有操作(隱藏)
請幫我。 謝謝。
由於明顯的隱私原因,這是不可能的,除非通過root用戶。 您試圖利用的安全漏洞已經關閉了一段時間。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.