android开发分享在Android 4.0及以上版本中以编程方式打开和closuresGPS?

您好,我正在创build一个防盗应用程序,通过短信find我的手机,它完美的工作,直到2.3。 但在4.0我不能以编程方式打开或closuresGPS是否有任何其他可能的方式来通过代码开关GPS。

    尝试使用此代码。 它适用于所有版本的我。

    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(ctx.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")); this.ctx.sendBroadcast(poke); } } // automatic turn off the gps public void turnGPSOff() { String provider = Settings.Secure.getString(ctx.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")); this.ctx.sendBroadcast(poke); } } 

      以上就是android开发分享在Android 4.0及以上版本中以编程方式打开和closuresGPS?相关内容,想了解更多android开发(异常处理)及android游戏开发关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/addevelopment/520368.html

      (0)
      上一篇 2020年12月6日
      下一篇 2020年12月6日

      精彩推荐