List of usage examples for android.provider Settings ACTION_LOCATION_SOURCE_SETTINGS
String ACTION_LOCATION_SOURCE_SETTINGS
To view the source code for android.provider Settings ACTION_LOCATION_SOURCE_SETTINGS.
Click Source Link
From source file:com.polyvi.xface.extension.XAppExt.java
/** * ?componen//from w ww.java2 s .c o m * * @param componenName * ??componen?? return true??,false? */ private boolean startSystemComponent(int componentCode) { SysComponent componentName = SysComponent.UNKNOWN; try { componentName = SysComponent.values()[componentCode]; } catch (ArrayIndexOutOfBoundsException e) { XLog.d(CLASS_NAME, "unkown component name!", e); return false; } Intent intent = null; boolean success = false; switch (componentName) { case VPN_CONFIG: intent = new Intent("android.net.vpn.SETTINGS"); break; case WIRELESS_CONFIG: intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS); break; case GPS_CONFIG: intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); break; default: XLog.d(CLASS_NAME, "unkown component name!"); break; } if (null != intent) { intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getContext().startActivity(intent); success = true; } return success; }
From source file:com.google.android.apps.paco.ExperimentExecutorCustomRendering.java
void launchGpsSettings() { startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)); }
From source file:org.wso2.edgeanalyticsservice.LocationSystemService.java
/** Initialize the location system Service and set the minimal update distance and time */ public void startLocationService(Context context) { mContext = context;//from w w w . j a v a 2s . c om mLocationManager = (LocationManager) mContext.getSystemService(mContext.LOCATION_SERVICE); Criteria locationCritera = new Criteria(); locationCritera.setAccuracy(Criteria.ACCURACY_COARSE); locationCritera.setAltitudeRequired(false); locationCritera.setBearingRequired(false); locationCritera.setCostAllowed(true); locationCritera.setPowerRequirement(Criteria.NO_REQUIREMENT); String providerName = mLocationManager.getBestProvider(locationCritera, true); if (providerName != null && mLocationManager.isProviderEnabled(providerName)) { if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public // void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. Log.e("Location", "No permission"); return; } mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MINIMUM_TIME_BETWEEN_UPDATES, (float) MINIMUM_DISTANCE_FOR_UPDATES, new MyLocationListner(), Looper.getMainLooper()); mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MINIMUM_TIME_BETWEEN_UPDATES, (float) MINIMUM_DISTANCE_FOR_UPDATES, new MyLocationListner(), Looper.getMainLooper()); mlocation = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); // mTaskManager.sendLocationData(new double[]{mlocation.getLatitude(), mlocation.getLongitude()}); mLocationListner = new MyLocationListner(); synchronized (this) { started = true; } } else { // Provider not enabled, prompt user to enable it Toast.makeText(mContext, "Please turn on GPS", Toast.LENGTH_LONG).show(); Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mContext.startActivity(myIntent); } }
From source file:com.android.gpstest.GpsTestActivity.java
/** * Ask the user if they want to enable GPS *//*from w ww . j av a 2 s.c o m*/ private void promptEnableGps() { new AlertDialog.Builder(this).setMessage(getString(R.string.enable_gps_message)) .setPositiveButton(getString(R.string.enable_gps_positive_button), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(intent); } }) .setNegativeButton(getString(R.string.enable_gps_negative_button), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }) .show(); }
From source file:com.mycompany.myfirstindoorsapp.PagedActivity.java
private void checkLocationIsEnabled() { // On android Marshmallow we also need to have active Location Services (GPS or Network based) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); boolean isNetworkLocationProviderEnabled = locationManager .isProviderEnabled(LocationManager.NETWORK_PROVIDER); boolean isGPSLocationProviderEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); if (!isGPSLocationProviderEnabled && !isNetworkLocationProviderEnabled) { // Only if both providers are disabled we need to ask the user to do something Toast.makeText(this, "Location is off, enable it in system settings.", Toast.LENGTH_LONG).show(); Intent locationInSettingsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); this.startActivityForResult(locationInSettingsIntent, REQUEST_CODE_LOCATION); } else {//w w w . j a v a2 s.c o m continueLoading(); } } else { continueLoading(); } }
From source file:com.ecoplayer.beta.MainActivity.java
private void showAlertMessageGps() { final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(getResources().getString(R.string.gps_message)).setCancelable(false) .setPositiveButton(getResources().getString(R.string.yes), new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int id) { startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)); }/*w w w . ja v a 2 s.com*/ }).setNegativeButton(getResources().getString(R.string.no), new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int id) { dialog.cancel(); } }); final AlertDialog alert = builder.create(); alert.show(); }
From source file:com.patil.geobells.lite.MainActivity.java
public void checkLocationServicesEnabled() { LocationManager lm = null;//from ww w . j a v a 2 s . com boolean gps_enabled = true, network_enabled = true; if (lm == null) lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 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) { AlertDialog.Builder dialog = new AlertDialog.Builder(this); dialog.setTitle(R.string.dialog_title_enable_locationservices); dialog.setMessage(getString(R.string.dialog_message_enable_locationservices)); dialog.setCancelable(false); dialog.setPositiveButton(getString(R.string.dialog_button_open_location_settings), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface paramDialogInterface, int paramInt) { paramDialogInterface.dismiss(); Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(myIntent); } }); dialog.setNegativeButton(getString(R.string.dialog_button_nothanks), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface paramDialogInterface, int paramInt) { finish(); } }); dialog.create().show(); } }
From source file:org.wso2.iot.agent.activities.AlreadyRegisteredActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_already_registered); textViewLastSync = (TextView) findViewById(R.id.textViewLastSync); imageViewRefresh = (ImageView) findViewById(R.id.imageViewRefresh); devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); cdmDeviceAdmin = new ComponentName(this, AgentDeviceAdminReceiver.class); context = this; DeviceInfo info = new DeviceInfo(context); Bundle extras = getIntent().getExtras(); if (extras != null) { if (extras.containsKey(getResources().getString(R.string.intent_extra_fresh_reg_flag))) { isFreshRegistration = extras .getBoolean(getResources().getString(R.string.intent_extra_fresh_reg_flag)); }//from w w w . ja va 2 s . co m } String registrationId = Preference.getString(context, Constants.PreferenceFlag.REG_ID); if (registrationId != null && !registrationId.isEmpty()) { regId = registrationId; } else { regId = info.getDeviceId(); } if (isFreshRegistration) { Preference.putBoolean(context, Constants.PreferenceFlag.REGISTERED, true); if (!isDeviceAdminActive()) { startEvents(); } // In FCM, for fresh registrations, the initial FCM notification has been ignored // purposely to avoid calling the server during enrollment flow and causing threading // issues. Therefore after initial enrollment, pending operations is called manually. if (Constants.NOTIFIER_FCM .equals(Preference.getString(context, Constants.PreferenceFlag.NOTIFIER_TYPE))) { MessageProcessor messageProcessor = new MessageProcessor(context); try { if (Preference.getBoolean(context, Constants.PreferenceFlag.REGISTERED)) { messageProcessor.getMessages(); } } catch (AndroidAgentException e) { Log.e(TAG, "Failed to perform operation", e); } } isFreshRegistration = false; } RelativeLayout relativeLayoutSync = (RelativeLayout) findViewById(R.id.layoutSync); relativeLayoutSync.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (Preference.getBoolean(context, Constants.PreferenceFlag.REGISTERED) && isDeviceAdminActive()) { syncWithServer(); } } }); RelativeLayout relativeLayoutDeviceInfo = (RelativeLayout) findViewById(R.id.layoutDeviceInfo); relativeLayoutDeviceInfo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { loadDeviceInfoActivity(); } }); RelativeLayout relativeLayoutChangePIN = (RelativeLayout) findViewById(R.id.layoutChangePIN); relativeLayoutChangePIN.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { loadPinCodeActivity(); } }); RelativeLayout relativeLayoutRegistration = (RelativeLayout) findViewById(R.id.layoutRegistration); if (Constants.HIDE_UNREGISTER_BUTTON) { relativeLayoutRegistration.setVisibility(View.GONE); } else { relativeLayoutRegistration.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showUnregisterDialog(); } }); } TextView textViewAgentVersion = (TextView) findViewById(R.id.textViewVersion); String versionText = BuildConfig.BUILD_TYPE + " v" + BuildConfig.VERSION_NAME + " (" + BuildConfig.VERSION_CODE + ") "; textViewAgentVersion.setText(versionText); if (Build.VERSION.SDK_INT >= 23) { List<String> missingPermissions = new ArrayList<>(); if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) { missingPermissions.add(android.Manifest.permission.READ_PHONE_STATE); } if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { missingPermissions.add(android.Manifest.permission.ACCESS_COARSE_LOCATION); } if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { missingPermissions.add(android.Manifest.permission.ACCESS_FINE_LOCATION); } if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { missingPermissions.add(android.Manifest.permission.WRITE_EXTERNAL_STORAGE); } NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // This is to handle permission obtaining for Android N devices where operations such // as mute that can cause a device to go into "do not disturb" will need additional // permission. Added here as well to support already enrolled devices to optain the // permission without reenrolling. if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M && !devicePolicyManager.isProfileOwnerApp(Constants.AGENT_PACKAGE) && notificationManager != null && !notificationManager.isNotificationPolicyAccessGranted()) { CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context, getResources().getString(R.string.dialog_do_not_distrub_title), getResources().getString(R.string.dialog_do_not_distrub_message), getResources().getString(R.string.ok), doNotDisturbClickListener); } if (missingPermissions.isEmpty()) { NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.cancel(Constants.PERMISSION_MISSING, Constants.PERMISSION_MISSING_NOTIFICATION_ID); } else { ActivityCompat.requestPermissions(AlreadyRegisteredActivity.this, missingPermissions.toArray(new String[missingPermissions.size()]), 110); } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { try { int locationSetting = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE); if (locationSetting == 0) { Intent enableLocationIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(enableLocationIntent); Toast.makeText(context, R.string.msg_need_location, Toast.LENGTH_LONG).show(); } } catch (Settings.SettingNotFoundException e) { Log.w(TAG, "Location setting is not available on this device"); } } boolean isRegistered = Preference.getBoolean(context, Constants.PreferenceFlag.REGISTERED); if (isRegistered) { if (CommonUtils.isNetworkAvailable(context)) { String serverIP = Constants.DEFAULT_HOST; String prefIP = Preference.getString(context, Constants.PreferenceFlag.IP); if (prefIP != null) { serverIP = prefIP; } regId = Preference.getString(context, Constants.PreferenceFlag.REG_ID); if (regId != null) { if (serverIP != null && !serverIP.isEmpty()) { ServerConfig utils = new ServerConfig(); utils.setServerIP(serverIP); if (utils.getHostFromPreferences(context) != null && !utils.getHostFromPreferences(context).isEmpty()) { CommonUtils.callSecuredAPI(AlreadyRegisteredActivity.this, utils.getAPIServerURL(context) + Constants.DEVICES_ENDPOINT + regId + Constants.IS_REGISTERED_ENDPOINT, HTTP_METHODS.GET, null, AlreadyRegisteredActivity.this, Constants.IS_REGISTERED_REQUEST_CODE); } else { try { CommonUtils.clearAppData(context); } catch (AndroidAgentException e) { String msg = "Device already dis-enrolled."; Log.e(TAG, msg, e); } loadInitialActivity(); } } else { Log.e(TAG, "There is no valid IP to contact server"); } } } else { if (!Constants.HIDE_ERROR_DIALOG) { CommonDialogUtils.showNetworkUnavailableMessage(AlreadyRegisteredActivity.this); } } } else { loadInitialActivity(); } }
From source file:br.liveo.ndrawer.ui.fragment.MainFragment.java
private void enableGPS() { AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity()); dialog.setTitle(" (GPS) "); dialog.setMessage(//from w ww . j a v a 2 s . c om "?? (GPS) . (GPS) ? ?"); dialog.setPositiveButton("", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Intent enableGPSIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivityForResult(enableGPSIntent, 1); } }).setNegativeButton("", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { return; } }).create().show(); }
From source file:com.dvn.vindecoder.ui.seller.AddDriverActivity.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 = "User sucessfully inserted"; builder.setMessage(message).setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface d, int id) { activity.startActivity(new Intent(action)); d.dismiss();/*from w w w .j a v a 2s .c om*/ } }); builder.create().show(); }