How to turn on the GPS on Android

后端 未结 7 634
[愿得一人]
[愿得一人] 2020-12-08 08:52

I am developing an android app which needs to activate the GPS.

I read a lot of topics in a lot of forums and the answer I\'ve found is:

it\'

7条回答
  •  悲&欢浪女
    2020-12-08 09:11

    Use this code //turnGPSON called After setcontentView(xml)

     private void turnGPSOn() {
    
        String provider = android.provider.Settings.Secure.getString(
                getContentResolver(),
                android.provider.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"));
            sendBroadcast(poke);
        }
    }**
    

提交回复
热议问题