Android Question how to convert the following to B4A

kalarius

Active Member
Licensed User
Longtime User
privatevoid turnGPSOn(){String provider =Settings.Secure.getString(getContentResolver(),Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

if(!provider.contains("gps")){//if gps is disabledfinalIntent poke =newIntent();
poke.setClassName("com.android.settings","com.android.settings.widget.SettingsAppWidgetProvider");
poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
poke.setData(Uri.parse("3"));
sendBroadcast(poke);}}

privatevoid turnGPSOff(){String provider =Settings.Secure.getString(getContentResolver(),Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

if(provider.contains("gps")){//if gps is enabledfinalIntent poke =newIntent();
poke.setClassName("com.android.settings","com.android.settings.widget.SettingsAppWidgetProvider");
poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
poke.setData(Uri.parse("3"));
sendBroadcast(poke);}}
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Settings.Secure.LOCATION_PROVIDERS_ALLOWED = "location_providers_allowed"
Intent.CATEGORY_ALTERNATIVE = "android.intent.category.ALTERNATIVE"
B4X:
Dim p As Phone
Dim provider As String = p.GetSettings("location_providers_allowed")
Log(provider)
Dim poke As Intent
poke.Initialize("", "3")
poke.AddCategory("android.intent.category.ALTERNATIVE")
p.SendBroadcastIntent(poke)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…