Android 4.1.2 如何以编程方式关闭 GPS [英] Android 4.1.2 How to turn off GPS programmatically

查看:30
本文介绍了Android 4.1.2 如何以编程方式关闭 GPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I am trying to switch on GPS by code. The following is the code I've used.

String provider = Settings.Secure.getString(context.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")); 
    context.sendBroadcast(poke);

The code executing in OnReceive function. What am I doing wrong?

解决方案

Android Guidelines have changed above version 4.0. You cannot change GPS off on programmatically for versions above 4.0. However, you can change wifi off on programmatically

这篇关于Android 4.1.2 如何以编程方式关闭 GPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆