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:com.example.android.expandingcells.ExpandingCells.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Get the location manager
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    // Define the criteria how to select the location provider
    criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_COARSE); //default

    criteria.setCostAllowed(false);//from   w w w.  j av  a 2s. c o  m
    // get the best provider depending on the criteria
    provider = locationManager.getBestProvider(criteria, false);

    // the last known location of this provider
    Location location = locationManager.getLastKnownLocation(provider);

    mylistener = new MyLocationListener();

    if (location != null) {
        mylistener.onLocationChanged(location);
    } else {
        // leads to the settings because there is no last known location
        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        startActivity(intent);
    }
    // location updates: at least 1 meter and 200millsecs change
    //NETWORK_PROVIDER
    locationManager.requestLocationUpdates(provider, 200, 1, mylistener);

    this.NewsList = new ArrayList<News>(4);
    for (int i = 0; i < 4; i++) {
        NewsList.add(new News());
    }

    //Methods to populate the Object
    getColor();
    getHoroscope();
    getRaghukalam();
    //getWeather();

    //Log.d("DEBUG", Byte.getBody());
    Log.d("DEBUG", "Print");
    // Toast.makeText(this, Byte.size(), Toast.LENGTH_LONG).show();

    ExpandableListItem[] values = new ExpandableListItem[] {
            new ExpandableListItem("Color", R.drawable.mb_color, CELL_DEFAULT_HEIGHT,
                    NewsList.get(0).getBody()),
            new ExpandableListItem("Horoscope", R.drawable.mb_horoscope, CELL_DEFAULT_HEIGHT,
                    NewsList.get(1).getBody()),
            new ExpandableListItem("Raghukalam", R.drawable.mb_raghukalam, CELL_DEFAULT_HEIGHT,
                    NewsList.get(2).getBody()),
            new ExpandableListItem("Weather", R.drawable.mb_weather, CELL_DEFAULT_HEIGHT,
                    NewsList.get(3).getBody()), };

    List<ExpandableListItem> mData = new ArrayList<ExpandableListItem>();

    for (int i = 0; i < NUM_OF_CELLS; i++) {
        ExpandableListItem obj = values[i % values.length];
        mData.add(new ExpandableListItem(obj.getTitle(), obj.getImgResource(), obj.getCollapsedHeight(),
                obj.getText()));
    }

    // CustomArrayAdapter adapter = new CustomArrayAdapter(this, R.layout.list_view_item, mData);
    adapter = new CustomArrayAdapter(this, R.layout.list_view_item, mData);

    mListView = (ExpandingListView) findViewById(R.id.main_list_view);
    mListView.setAdapter(adapter);
    mListView.setDivider(null);
}

From source file:com.djit.mixfader.sample.BaseActivity.java

/**
 * Handles permissions and features needed by the app
 *//*from   ww  w.java2 s  . c o  m*/
@Override
protected void onResume() {
    super.onResume();

    // Asks for Bluetooth activation is needed
    final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    final BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
    if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) {
        final Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
    }

    // Asks for permissions if needed
    final int checkCoarseLocation = ContextCompat.checkSelfPermission(this,
            "android.permission.ACCESS_COARSE_LOCATION");
    final int checkFineLocation = ContextCompat.checkSelfPermission(this,
            "android.permission.ACCESS_FINE_LOCATION");
    if (checkCoarseLocation == PackageManager.PERMISSION_DENIED
            && checkFineLocation == PackageManager.PERMISSION_DENIED) {
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_COARSE_LOCATION },
                MY_PERMISSIONS_REQUEST_COARSE_LOCATION);
    } else {
        // Ask for location service if needed
        if (needToEnableLocation(this)) {
            final Intent viewIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            startActivity(viewIntent);
        }
    }
}

From source file:com.nextgis.maplibui.util.NotificationHelper.java

private static void showLocationDialog(final Context context, String title, String info) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(title).setMessage(info)
            .setPositiveButton(R.string.action_settings, new DialogInterface.OnClickListener() {
                @Override//from w w w  . j  a va  2  s  .  c  om
                public void onClick(DialogInterface dialog, int id) {
                    context.startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                }
            }).setNegativeButton(android.R.string.cancel, null)
            .setNeutralButton(R.string.do_not_ask_again, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context)
                            .edit();
                    editor.putBoolean(SettingsConstantsUI.KEY_PREF_SHOW_GEO_DIALOG, false).commit();
                }
            });
    builder.create();
    builder.show();
}

From source file:com.example.demo_dv_fuse.MapScreen.java

/**
 * @see android.app.Activity#onCreate(android.os.Bundle)
 *///  w  w  w  . j  a va 2 s  .  c o  m
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map_screen);
    this.map = ((MapFragment) getFragmentManager().findFragmentById(R.id.mapView)).getMap();
    this.map.setMapType(GoogleMap.MAP_TYPE_NORMAL);

    final int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());

    if (status == ConnectionResult.SUCCESS) { // Google Play Services is available
        // Enabling MyLocation Layer of Google Map
        this.map.setMyLocationEnabled(true);

        // Getting LocationManager object from System Service LOCATION_SERVICE
        final LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

        // Creating a criteria object to retrieve provider
        final Criteria criteria = new Criteria();

        // Getting the name of the best provider
        final String provider = locationManager.getBestProvider(criteria, true);

        // Getting Current Location
        final Location location = locationManager.getLastKnownLocation(provider);

        if (location != null) {
            onLocationChanged(location);
            //            } else {
            //                final String coordinates[] = {"1.352566007", "103.78921587"};
            //                final double lat = Double.parseDouble(coordinates[0]);
            //                final double lng = Double.parseDouble(coordinates[1]);
            //
            //                // Creating a LatLng object for the current location
            //                LatLng latLng = new LatLng(lat, lng);
            //
            //                // Showing the current location in Google Map
            //                this.map.moveCamera(CameraUpdateFactory.newLatLng(latLng));
            //                this.map.animateCamera(CameraUpdateFactory.zoomTo(15));
        }
        boolean enabledGPS = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
        boolean enabledWiFi = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

        // Check if enabled and if not send user to the GSP settings
        // Better solution would be to display a dialog and suggesting to 
        // go to the settings
        if (!enabledGPS || !enabledWiFi) {
            Toast.makeText(this, "GPS signal not found", Toast.LENGTH_LONG).show();
            Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            startActivity(intent);
        }
        locationManager.requestLocationUpdates(provider, 20000, 0, this);
    } else { // Google Play Services are not available
        final int requestCode = 10;
        final Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
        dialog.show();
    }
}

From source file:com.phonegap.plugins.nativesettings.NativeSettings.java

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    PluginResult.Status status = PluginResult.Status.OK;
    Uri packageUri = Uri.parse("package:" + this.cordova.getActivity().getPackageName());
    String result = "";

    //Information on settings can be found here:
    //http://developer.android.com/reference/android/provider/Settings.html

    action = args.getString(0);//from  w w w. j a  v a 2  s .  c o m
    Intent intent = null;

    if (action.equals("accessibility")) {
        intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
    } else if (action.equals("account")) {
        intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT);
    } else if (action.equals("airplane_mode")) {
        intent = new Intent(android.provider.Settings.ACTION_AIRPLANE_MODE_SETTINGS);
    } else if (action.equals("apn")) {
        intent = new Intent(android.provider.Settings.ACTION_APN_SETTINGS);
    } else if (action.equals("application_details")) {
        intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS, packageUri);
    } else if (action.equals("application_development")) {
        intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
    } else if (action.equals("application")) {
        intent = new Intent(android.provider.Settings.ACTION_APPLICATION_SETTINGS);
    }
    //else if (action.equals("battery_saver")) {
    //    intent = new Intent(android.provider.Settings.ACTION_BATTERY_SAVER_SETTINGS);
    //}
    else if (action.equals("bluetooth")) {
        intent = new Intent(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS);
    } else if (action.equals("captioning")) {
        intent = new Intent(android.provider.Settings.ACTION_CAPTIONING_SETTINGS);
    } else if (action.equals("cast")) {
        intent = new Intent(android.provider.Settings.ACTION_CAST_SETTINGS);
    } else if (action.equals("data_roaming")) {
        intent = new Intent(android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS);
    } else if (action.equals("date")) {
        intent = new Intent(android.provider.Settings.ACTION_DATE_SETTINGS);
    } else if (action.equals("about")) {
        intent = new Intent(android.provider.Settings.ACTION_DEVICE_INFO_SETTINGS);
    } else if (action.equals("display")) {
        intent = new Intent(android.provider.Settings.ACTION_DISPLAY_SETTINGS);
    } else if (action.equals("dream")) {
        intent = new Intent(android.provider.Settings.ACTION_DREAM_SETTINGS);
    } else if (action.equals("home")) {
        intent = new Intent(android.provider.Settings.ACTION_HOME_SETTINGS);
    } else if (action.equals("keyboard")) {
        intent = new Intent(android.provider.Settings.ACTION_INPUT_METHOD_SETTINGS);
    } else if (action.equals("keyboard_subtype")) {
        intent = new Intent(android.provider.Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS);
    } else if (action.equals("storage")) {
        intent = new Intent(android.provider.Settings.ACTION_INTERNAL_STORAGE_SETTINGS);
    } else if (action.equals("locale")) {
        intent = new Intent(android.provider.Settings.ACTION_LOCALE_SETTINGS);
    } else if (action.equals("location")) {
        intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
    } else if (action.equals("manage_all_applications")) {
        intent = new Intent(android.provider.Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
    } else if (action.equals("manage_applications")) {
        intent = new Intent(android.provider.Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS);
    } else if (action.equals("memory_card")) {
        intent = new Intent(android.provider.Settings.ACTION_MEMORY_CARD_SETTINGS);
    } else if (action.equals("network")) {
        intent = new Intent(android.provider.Settings.ACTION_NETWORK_OPERATOR_SETTINGS);
    } else if (action.equals("nfcsharing")) {
        intent = new Intent(android.provider.Settings.ACTION_NFCSHARING_SETTINGS);
    } else if (action.equals("nfc_payment")) {
        intent = new Intent(android.provider.Settings.ACTION_NFC_PAYMENT_SETTINGS);
    } else if (action.equals("nfc_settings")) {
        intent = new Intent(android.provider.Settings.ACTION_NFC_SETTINGS);
    }
    //else if (action.equals("notification_listner")) {
    //    intent = new Intent(android.provider.Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS);
    //}
    else if (action.equals("print")) {
        intent = new Intent(android.provider.Settings.ACTION_PRINT_SETTINGS);
    } else if (action.equals("privacy")) {
        intent = new Intent(android.provider.Settings.ACTION_PRIVACY_SETTINGS);
    } else if (action.equals("quick_launch")) {
        intent = new Intent(android.provider.Settings.ACTION_QUICK_LAUNCH_SETTINGS);
    } else if (action.equals("search")) {
        intent = new Intent(android.provider.Settings.ACTION_SEARCH_SETTINGS);
    } else if (action.equals("security")) {
        intent = new Intent(android.provider.Settings.ACTION_SECURITY_SETTINGS);
    } else if (action.equals("settings")) {
        intent = new Intent(android.provider.Settings.ACTION_SETTINGS);
    } else if (action.equals("show_regulatory_info")) {
        intent = new Intent(android.provider.Settings.ACTION_SHOW_REGULATORY_INFO);
    } else if (action.equals("sound")) {
        intent = new Intent(android.provider.Settings.ACTION_SOUND_SETTINGS);
    } else if (action.equals("store")) {
        intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("market://details?id=" + this.cordova.getActivity().getPackageName()));
    } else if (action.equals("sync")) {
        intent = new Intent(android.provider.Settings.ACTION_SYNC_SETTINGS);
    } else if (action.equals("usage")) {
        intent = new Intent(android.provider.Settings.ACTION_USAGE_ACCESS_SETTINGS);
    } else if (action.equals("user_dictionary")) {
        intent = new Intent(android.provider.Settings.ACTION_USER_DICTIONARY_SETTINGS);
    } else if (action.equals("voice_input")) {
        intent = new Intent(android.provider.Settings.ACTION_VOICE_INPUT_SETTINGS);
    } else if (action.equals("wifi_ip")) {
        intent = new Intent(android.provider.Settings.ACTION_WIFI_IP_SETTINGS);
    } else if (action.equals("wifi")) {
        intent = new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS);
    } else if (action.equals("wireless")) {
        intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS);
    } else {
        status = PluginResult.Status.INVALID_ACTION;
        callbackContext.sendPluginResult(new PluginResult(status, result));
        return false;
    }

    if (args.length() > 1 && args.getBoolean(1)) {
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    }
    this.cordova.getActivity().startActivity(intent);

    callbackContext.sendPluginResult(new PluginResult(status, result));
    return true;
}

From source file:com.rsamadhan.MainActivity.java

private void showGPSDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    builder.setMessage(R.string.enable_gps)
            .setPositiveButton(R.string.enable_gps_txt, new DialogInterface.OnClickListener() {
                @Override/*from  w ww .j av  a  2s  .  c  om*/
                public void onClick(DialogInterface dialog, int which) {
                    Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                    startActivity(intent);
                }
            }).setNegativeButton(R.string.no_txt, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).setCancelable(false);

    builder.create().show();
}

From source file:com.dealsmessanger.android.DemoActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);/*www.jav  a2s.c om*/
    mDisplay = (TextView) findViewById(R.id.display);

    context = getApplicationContext();

    // Check device for Play Services APK. If check succeeds, proceed with GCM registration.
    //        if (checkPlayServices()) {
    //            gcm = GoogleCloudMessaging.getInstance(this);
    //            regid = getRegistrationId(context);
    //
    //            if (regid.isEmpty()) {
    //                registerInBackground();
    //            }
    //        } else {
    //            Log.i(TAG, "No valid Google Play Services APK found.");
    //        }
    registerInBackground();
    // Get the location manager
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    // Define the criteria how to select the location provider
    criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_COARSE); // default

    criteria.setCostAllowed(false);
    // get the best provider depending on the criteria
    provider = locationManager.getBestProvider(criteria, false);

    // the last known location of this provider
    location = locationManager.getLastKnownLocation(provider);

    mylistener = new MyLocationListener();

    if (location != null) {
        mylistener.onLocationChanged(location);
    } else {
        // leads to the settings because there is no last known location
        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        startActivity(intent);
    }
    // location updates: at least 1 meter and 200millsecs change
    locationManager.requestLocationUpdates(provider, 200, 1, mylistener);

}

From source file:br.com.sigacon.coletaDados.FragmentParcelasTabsPager.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.fragment_tabs_pager);
    setTitle(R.string.dados_parcela);/*ww w  .  j a  va 2  s.  com*/
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    mTabHost = (TabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup();

    mViewPager = (ViewPager) findViewById(R.id.pager);

    mTabsAdapter = new TabsAdapter(this, mTabHost, mViewPager);

    mTabsAdapter.addTab(mTabHost.newTabSpec("maps").setIndicator(getString(R.string.mapa)),
            FragmentParcelasMap.CountingFragment.class, null);
    mTabsAdapter.addTab(mTabHost.newTabSpec("form").setIndicator(getString(R.string.formulario_parcela)),
            FragmentParcelasForm.CountingFragment.class, null);

    if (savedInstanceState != null) {
        mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab"));
    }

    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            String provider = Settings.Secure.getString(getContentResolver(),
                    Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
            //Se vier null ou length == 0    por que o GPS esta desabilitado. 

            Log.e("sigaLog", "provider " + String.valueOf(provider == null) + " ou "
                    + ((provider.contains("gps")) ? provider : "not Gps"));
            if (provider == null || !provider.contains("gps")) {
                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                        FragmentParcelasTabsPager.this);
                // Seta o Titulo do Dialog
                alertDialogBuilder.setTitle(R.string.atencao);
                Log.e("sigaLog", "alertDialogBuilder.setTitle");
                // seta a mensagem
                alertDialogBuilder.setMessage(R.string.gps_desativado);
                alertDialogBuilder.setCancelable(false)
                        .setPositiveButton(R.string.sim, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                //Para abrir a tela do menu pode fazer assim:   
                                Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                                startActivityForResult(intent, 1);
                            }
                        }).setNegativeButton(R.string.nao, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                            }
                        });

                // Cria o alertDialog com o conteudo do alertDialogBuilder
                AlertDialog alertDialog = alertDialogBuilder.create();
                Log.e("sigaLog", "alertDialog.create");
                // Exibe o Dialog
                alertDialog.show();
                Log.e("sigaLog", "alertDialog.show");
            }
        }
    }, 1000);
}

From source file:com.nextgis.maplibui.util.NotificationHelper.java

private static void showLocationNotification(Context context, String title, String info) {
    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Intent locationSettings = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
    PendingIntent intentNotify = PendingIntent.getActivity(context, 0, locationSettings,
            PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setContentIntent(intentNotify)
            .setAutoCancel(true).setSmallIcon(R.drawable.ic_location).setContentTitle(title)
            .setContentText(info).setTicker(title);

    manager.notify(NOTIFICATION_GPS_ID, builder.build());
}

From source file:ch.luethi.skylinestracker.MainActivity.java

public void startStopTracking(View view) {
    CheckBox cb = (CheckBox) view;//from  w  w  w  .j  a va 2s.c o  m
    if (cb.isChecked()) {
        String provider = Settings.Secure.getString(getContentResolver(),
                Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
        if (!provider.contains("gps")) {
            Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            startActivity(intent);
        }
        LocalBroadcastManager.getInstance(this).registerReceiver(onStatusChange, brFilter);
        startService(positionService);
        statusText.setText(R.string.on);
    } else {
        LocalBroadcastManager.getInstance(this).unregisterReceiver(onStatusChange);
        stopService(positionService);
        statusText.setText(R.string.off);
    }
}