Example usage for android.provider Settings ACTION_LOCATION_SOURCE_SETTINGS

List of usage examples for android.provider Settings ACTION_LOCATION_SOURCE_SETTINGS

Introduction

In this page you can find the example usage for android.provider Settings ACTION_LOCATION_SOURCE_SETTINGS.

Prototype

String ACTION_LOCATION_SOURCE_SETTINGS

To view the source code for android.provider Settings ACTION_LOCATION_SOURCE_SETTINGS.

Click Source Link

Document

Activity Action: Show settings to allow configuration of current location sources.

Usage

From source file:mgks.os.webview.MainActivity.java

public void show_notification(int type, int id) {
    long when = System.currentTimeMillis();
    asw_notification = (NotificationManager) MainActivity.this.getSystemService(Context.NOTIFICATION_SERVICE);
    Intent i = new Intent();
    if (type == 1) {
        i.setClass(MainActivity.this, MainActivity.class);
    } else if (type == 2) {
        i.setAction(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
    } else {//from www .j a  v a 2  s .c  o m
        i.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        i.addCategory(Intent.CATEGORY_DEFAULT);
        i.setData(Uri.parse("package:" + MainActivity.this.getPackageName()));
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    }
    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0, i,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(MainActivity.this, "");
    switch (type) {
    case 1:
        builder.setTicker(getString(R.string.app_name));
        builder.setContentTitle(getString(R.string.loc_fail));
        builder.setContentText(getString(R.string.loc_fail_text));
        builder.setStyle(new NotificationCompat.BigTextStyle().bigText(getString(R.string.loc_fail_more)));
        builder.setVibrate(new long[] { 350, 350, 350, 350, 350 });
        builder.setSmallIcon(R.mipmap.ic_launcher);
        break;

    case 2:
        builder.setTicker(getString(R.string.app_name));
        builder.setContentTitle(getString(R.string.loc_perm));
        builder.setContentText(getString(R.string.loc_perm_text));
        builder.setStyle(new NotificationCompat.BigTextStyle().bigText(getString(R.string.loc_perm_more)));
        builder.setVibrate(new long[] { 350, 700, 350, 700, 350 });
        builder.setSound(alarmSound);
        builder.setSmallIcon(R.mipmap.ic_launcher);
        break;
    }
    builder.setOngoing(false);
    builder.setAutoCancel(true);
    builder.setContentIntent(pendingIntent);
    builder.setWhen(when);
    builder.setContentIntent(pendingIntent);
    asw_notification_new = builder.build();
    asw_notification.notify(id, asw_notification_new);
}

From source file:arc.noaa.weather.activities.MainActivity.java

private void showLocationSettingsDialog() {
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
    alertDialog.setTitle(R.string.location_settings);
    alertDialog.setMessage(R.string.location_settings_message);
    alertDialog.setPositiveButton(R.string.location_settings_button, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            startActivity(intent);// w  w w.j  av a  2 s . co  m
        }
    });
    alertDialog.setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });
    alertDialog.show();
}

From source file:com.dvn.vindecoder.ui.user.GetAllVehicalDetails.java

public static void displayPromptForEnablingGPS(final Activity activity) {

    final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    final String action = Settings.ACTION_LOCATION_SOURCE_SETTINGS;
    final String message = "Do you want open GPS setting?";

    builder.setMessage(message).setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface d, int id) {
            activity.startActivity(new Intent(action));
            d.dismiss();//from  ww w. j a v a  2s.c  o m
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface d, int id) {
            d.cancel();
        }
    });
    builder.create().show();
}

From source file:com.snt.bt.recon.activities.MainActivity.java

private void buildAlertMessageNoGps() {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Your GPS is currently disabled, do you want to manually enable it?")
            .setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, final int id) {
                    startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                }//w  ww  .  ja  va2 s  . c  o  m
            }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, final int id) {
                    dialog.cancel();
                    //close app
                    finishAffinity();

                }
            });
    final AlertDialog alert = builder.create();
    alert.show();

}

From source file:plugin.google.maps.GoogleMaps.java

@SuppressWarnings("unused")
private void getMyLocation(final JSONArray args, final CallbackContext callbackContext) throws JSONException {

    LocationManager locationManager = (LocationManager) this.activity
            .getSystemService(Context.LOCATION_SERVICE);
    List<String> providers = locationManager.getAllProviders();
    if (providers.size() == 0) {
        JSONObject result = new JSONObject();
        result.put("status", false);
        result.put("error_code", "not_available");
        result.put("error_message",
                "Since this device does not have any location provider, this app can not detect your location.");
        callbackContext.error(result);/*from w w  w  .j  a  v a  2  s  . c o m*/
        return;
    }

    // enableHighAccuracy = true -> PRIORITY_HIGH_ACCURACY
    // enableHighAccuracy = false -> PRIORITY_BALANCED_POWER_ACCURACY

    JSONObject params = args.getJSONObject(0);
    boolean isHigh = false;
    if (params.has("enableHighAccuracy")) {
        isHigh = params.getBoolean("enableHighAccuracy");
    }
    final boolean enableHighAccuracy = isHigh;

    String provider = null;
    if (enableHighAccuracy == true) {
        if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            provider = LocationManager.GPS_PROVIDER;
        } else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
            provider = LocationManager.NETWORK_PROVIDER;
        } else if (locationManager.isProviderEnabled(LocationManager.PASSIVE_PROVIDER)) {
            provider = LocationManager.PASSIVE_PROVIDER;
        }
    } else {
        if (locationManager.isProviderEnabled(LocationManager.PASSIVE_PROVIDER)) {
            provider = LocationManager.PASSIVE_PROVIDER;
        } else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
            provider = LocationManager.NETWORK_PROVIDER;
        } else if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            provider = LocationManager.GPS_PROVIDER;
        }
    }
    if (provider == null) {
        //Ask the user to turn on the location services.
        AlertDialog.Builder builder = new AlertDialog.Builder(this.activity);
        builder.setTitle("Improve location accuracy");
        builder.setMessage("To enhance your Maps experience:\n\n" + " - Enable Google apps location access\n\n"
                + " - Turn on GPS and mobile network location");
        builder.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //Launch settings, allowing user to make a change
                Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                activity.startActivity(intent);

                JSONObject result = new JSONObject();
                try {
                    result.put("status", false);
                    result.put("error_code", "open_settings");
                    result.put("error_message", "User opened the settings of location service. So try again.");
                } catch (JSONException e) {
                }
                callbackContext.error(result);
            }
        });
        builder.setNegativeButton("Skip", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //No location service, no Activity
                dialog.dismiss();

                JSONObject result = new JSONObject();
                try {
                    result.put("status", false);
                    result.put("error_code", "service_denied");
                    result.put("error_message", "This app has rejected to use Location Services.");
                } catch (JSONException e) {
                }
                callbackContext.error(result);
            }
        });
        builder.create().show();
        return;
    }

    Location location = locationManager.getLastKnownLocation(provider);
    if (location != null) {
        JSONObject result = PluginUtil.location2Json(location);
        result.put("status", true);
        callbackContext.success(result);
        return;
    }

    PluginResult tmpResult = new PluginResult(PluginResult.Status.NO_RESULT);
    tmpResult.setKeepCallback(true);
    callbackContext.sendPluginResult(tmpResult);

    locationClient = new LocationClient(this.activity, new ConnectionCallbacks() {

        @Override
        public void onConnected(Bundle bundle) {
            LocationRequest request = new LocationRequest();
            int priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY;
            if (enableHighAccuracy) {
                priority = LocationRequest.PRIORITY_HIGH_ACCURACY;
            }
            request.setPriority(priority);
            locationClient.requestLocationUpdates(request, new LocationListener() {

                @Override
                public void onLocationChanged(Location location) {
                    JSONObject result;
                    try {
                        result = PluginUtil.location2Json(location);
                        result.put("status", true);
                        callbackContext.success(result);
                    } catch (JSONException e) {
                    }
                    locationClient.disconnect();
                }

            });
        }

        @Override
        public void onDisconnected() {
        }

    }, new OnConnectionFailedListener() {

        @Override
        public void onConnectionFailed(ConnectionResult connectionResult) {
            int errorCode = connectionResult.getErrorCode();
            String errorMsg = GooglePlayServicesUtil.getErrorString(errorCode);
            PluginResult result = new PluginResult(PluginResult.Status.ERROR, errorMsg);
            callbackContext.sendPluginResult(result);
        }

    });
    locationClient.connect();
}

From source file:info.zamojski.soft.towercollector.MainActivity.java

private void askAndSetGpsEnabled() {
    if (GpsUtils.isGpsEnabled(getApplication())) {
        Log.d("askAndSetGpsEnabled(): GPS enabled");
        isGpsEnabled = true;//  www .ja  va 2  s. c  o m
        showAskForLocationSettingsDialog = false;
    } else {
        Log.d("askAndSetGpsEnabled(): GPS disabled, asking user");
        isGpsEnabled = false;
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.dialog_want_enable_gps)
                .setPositiveButton(R.string.dialog_yes, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        Log.d("askAndSetGpsEnabled(): display settings");
                        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                        try {
                            startActivity(intent);
                            showAskForLocationSettingsDialog = true;
                        } catch (ActivityNotFoundException ex1) {
                            intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
                            try {
                                startActivity(intent);
                                showAskForLocationSettingsDialog = true;
                            } catch (ActivityNotFoundException ex2) {
                                Log.w("askAndSetGpsEnabled(): Could not open Settings to enable GPS");
                                MyApplication.getAnalytics().sendException(ex2, Boolean.FALSE);
                                ACRA.getErrorReporter().handleSilentException(ex2);
                                AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this)
                                        .setMessage(R.string.dialog_could_not_open_gps_settings)
                                        .setPositiveButton(R.string.dialog_ok, null).create();
                                alertDialog.setCanceledOnTouchOutside(true);
                                alertDialog.setCancelable(true);
                                alertDialog.show();
                            }
                        } finally {
                            dialog.dismiss();
                        }
                    }
                }).setNegativeButton(R.string.dialog_no, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        Log.d("askAndSetGpsEnabled(): cancel");
                        dialog.cancel();
                        if (GpsUtils.isGpsEnabled(getApplication())) {
                            Log.d("askAndSetGpsEnabled(): provider enabled in the meantime");
                            startCollectorServiceWithCheck();
                        } else {
                            isGpsEnabled = false;
                            showAskForLocationSettingsDialog = false;
                        }
                    }
                });
        AlertDialog dialog = builder.create();
        dialog.setCanceledOnTouchOutside(true);
        dialog.setCancelable(true);
        dialog.show();
    }
}

From source file:obdii.starter.automotive.iot.ibm.com.iot4a_obdii.Home.java

private boolean setLocationInformation() {
    // returns false if GPS and Network settings are needed
    final ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(
            Context.CONNECTIVITY_SERVICE);
    final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();

    if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
            && (networkInfo != null && networkInfo.isConnected())) {
        if (ActivityCompat.checkSelfPermission(getApplicationContext(),
                Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                && ActivityCompat.checkSelfPermission(getApplicationContext(),
                        Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            return true;
        }/*from   w w w.  j a v  a2s .  c o  m*/

        locationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);

        final List<String> providers = locationManager.getProviders(true);
        Location finalLocation = null;

        for (String provider : providers) {
            if (ActivityCompat.checkSelfPermission(getApplicationContext(),
                    Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                    && ActivityCompat.checkSelfPermission(getApplicationContext(),
                            Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                return true;
            }

            final Location lastKnown = locationManager.getLastKnownLocation(provider);

            if (lastKnown == null) {
                continue;
            }
            if (finalLocation == null || (lastKnown.getAccuracy() < finalLocation.getAccuracy())) {
                finalLocation = lastKnown;
            }
        }

        if (finalLocation == null) {
            Log.e("Location Data", "Not Working!");
        } else {
            Log.d("Location Data", finalLocation.getLatitude() + " " + finalLocation.getLongitude() + "");
            location = finalLocation;
        }

        return true;
    } else {
        if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            Toast.makeText(getApplicationContext(), "Please turn on your GPS", Toast.LENGTH_LONG).show();

            final Intent gpsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            startActivityForResult(gpsIntent, GPS_INTENT);

            if (networkInfo == null) {
                networkIntentNeeded = true;
            }
            return false;
        } else {
            if (networkInfo == null) {
                Toast.makeText(getApplicationContext(), "Please turn on Mobile Data or WIFI", Toast.LENGTH_LONG)
                        .show();

                final Intent settingsIntent = new Intent(Settings.ACTION_SETTINGS);
                startActivityForResult(settingsIntent, SETTINGS_INTENT);
                return false;
            } else {
                return true;
            }
        }
    }
}

From source file:com.plusot.senselib.SenseMain.java

private void checkGPS() {
    if (PreferenceKey.GPSON.isTrue()) {
        final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

        if (manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            startUpDialogs("checkGPS.providerEnabled");
            return;
        }/*from  www.ja va  2  s.c o  m*/
        final AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.dialog_gps_on).setCancelable(true)
                .setPositiveButton(R.string.button_yes, new DialogInterface.OnClickListener() {
                    public void onClick(final DialogInterface dialog, final int id) {
                        startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS),
                                RESULT_GPS);
                    }
                }).setNegativeButton(R.string.button_no, new DialogInterface.OnClickListener() {
                    public void onClick(final DialogInterface dialog, final int id) {
                        //dialog.cancel();
                        startUpDialogs("checkGPS.dialog.negativeButton");
                    }
                }).setOnCancelListener(new OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface arg0) {
                        startUpDialogs("checkGPS.dialog.cancel");
                    }
                });
        final AlertDialog alert = builder.create();
        alert.show();
    } else
        startUpDialogs("checkGPS.gpsOff");
}

From source file:edu.usf.cutr.opentripplanner.android.fragments.MainFragment.java

@Override
public boolean onOptionsItemSelected(final MenuItem pItem) {
    OTPApp app = ((OTPApp) getActivity().getApplication());
    switch (pItem.getItemId()) {
    case R.id.gps_settings:
        Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        startActivity(myIntent);//w  ww. j  a va2  s  .  c o m
        break;
    case R.id.settings:
        getActivity().startActivityForResult(new Intent(getActivity(), SettingsActivity.class),
                OTPApp.SETTINGS_REQUEST_CODE);
        break;
    case R.id.feedback:
        Server selectedServer = app.getSelectedServer();

        String[] recipients = { selectedServer.getContactEmail(),
                getString(R.string.feedback_email_android_developer) };

        String uriText = "mailto:";
        for (String recipient : recipients) {
            uriText += recipient + ";";
        }

        String subject = "";
        subject += getResources().getString(R.string.menu_button_feedback_subject);
        Date d = Calendar.getInstance().getTime();
        subject += "[" + d.toString() + "]";
        uriText += "?subject=" + subject;

        String content = ((MyActivity) getActivity()).getCurrentRequestString();

        try {
            uriText += "&body=" + URLEncoder.encode(content, OTPApp.URL_ENCODING);
        } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
            return false;
        }

        Uri uri = Uri.parse(uriText);

        Intent sendIntent = new Intent(Intent.ACTION_SENDTO);
        sendIntent.setData(uri);
        startActivity(Intent.createChooser(sendIntent,
                getResources().getString(R.string.menu_button_feedback_send_email)));

        break;
    case R.id.server_info:
        Server server = app.getSelectedServer();

        if (server == null) {
            Log.w(OTPApp.TAG, "Tried to get server info when no server was selected");
            Toast.makeText(mApplicationContext,
                    mApplicationContext.getResources().getString(R.string.toast_no_server_selected_error),
                    Toast.LENGTH_SHORT).show();
            break;
        }

        WeakReference<Activity> weakContext = new WeakReference<Activity>(getActivity());

        ServerChecker serverChecker = new ServerChecker(weakContext, mApplicationContext, true);
        serverChecker.execute(server);

        break;
    default:
        break;
    }

    return false;
}

From source file:me.ububble.speakall.fragment.ConversationChatFragment.java

public void checkCountryLocation(final boolean gpsProvider, final boolean netProvider) {
    getActivity().runOnUiThread(new Runnable() {
        @Override/*www. jav  a 2  s.c o m*/
        public void run() {
            boolean gpsEnabled = false;
            boolean networkEnabled = false;
            if (gpsProvider) {
                gpsEnabled = milocManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
            }
            if (netProvider) {
                networkEnabled = milocManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
            }
            if (gpsProvider && netProvider) {
                if (!gpsEnabled && !networkEnabled) {
                    LayoutInflater dialogInflater = (LayoutInflater) activity
                            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    dialogView = dialogInflater.inflate(R.layout.null_contact_dialog, null);
                    TextView mensaje = (TextView) dialogView.findViewById(R.id.dialog_add_contact);
                    mensaje.setText(getString(R.string.location_services));
                    final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity)
                            .setView(dialogView).setCancelable(true)
                            .setPositiveButton(R.string.add_contact_yes, null)
                            .setNegativeButton(R.string.add_contact_no, null);
                    finderDialog = dialogBuilder.show();
                    finderDialog.setCanceledOnTouchOutside(true);
                    finderDialog.getButton(DialogInterface.BUTTON_POSITIVE)
                            .setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    finderDialog.dismiss();
                                    System.gc();
                                    dontClose = true;
                                    ((MainActivity) activity).dontClose = true;
                                    hideKeyBoard();
                                    Intent intent = new Intent(
                                            android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                                    startActivityForResult(intent, 45);
                                }
                            });
                    finderDialog.getButton(DialogInterface.BUTTON_NEGATIVE)
                            .setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    finderDialog.dismiss();
                                }
                            });
                } else {
                    milocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
                            ConversationChatFragment.this);
                    milocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,
                            ConversationChatFragment.this);
                }
            }
        }
    });
}