Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to check if location is enabled android

LocationManager lm = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
boolean gps_enabled = false;
boolean network_enabled = false;

try {
    gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
} catch(Exception ex) {}

try {
    network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
} catch(Exception ex) {}

if(!gps_enabled && !network_enabled) {
    // notify user
    new AlertDialog.Builder(context)
        .setMessage(R.string.gps_network_not_enabled)
        .setPositiveButton(R.string.open_location_settings, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface paramDialogInterface, int paramInt) {
                context.startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
            }
        }
        .setNegativeButton(R.string.Cancel,null)
        .show();    
}
Comment

PREVIOUS NEXT
Code Example
Java :: java double to string with comma 
Java :: android studio edittext text change listener 
Java :: java itemstatechanged called twice 
Java :: find the greatest number in hashmap 
Java :: how to get the time in java 
Java :: how to install java 11 jdk on ubuntu 20.04 
Java :: hello world in javacsript 
Java :: java bubble sort 
Java :: Duplicate class android.support.v4.app. 
Java :: java how to get elapsedTime 
Java :: force fullscreen jframe 
Java :: java robot left click 
Java :: java take screenshot 
Java :: calculate pi in java 
Java :: ubuntu java compiler version 
Java :: java check if bundle has property 
Java :: java reduce sum 
Java :: arraylist with values 
Java :: protocollib onenable 
Java :: bungeecord plugin add configs 
Java :: brxm remove property 
Java :: initialize hashset java 
Java :: Java get list of keys Hashmap 
Java :: how to build a java main menu 
Java :: android internet permission 
Java :: import for Collectors java 
Java :: jpa repository delete method return value 
Java :: add extension quarkus 
Java :: containskey java complexity 
Java :: android studio get string 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =