下面列出了android.provider.Settings#ACTION_LOCATION_SOURCE_SETTINGS 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void displayPromptForEnablingGPS() {
final String action = Settings.ACTION_LOCATION_SOURCE_SETTINGS;
new MaterialDialog.Builder(getActivity())
.title(R.string.label_request_open_gps_title)
.content(R.string.label_request_open_gps_content)
.positiveText(R.string.label_ok)
.onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) {
startActivityForResult(new Intent(action), REQUEST_CODE_OPEN_GPS);
}
})
.negativeText(R.string.label_cancel)
.cancelable(true)
.negativeText(R.string.label_cancel)
.show();
}
private void checkSettings() {
// Is GPS enabled?
final boolean gpsEnabled = locationTrackingEnabled();
// Is there internet connectivity?
final boolean internetConnected = internetConnectivity();
if (gpsEnabled && internetConnected) {
completeSetUp();
} else if (!gpsEnabled) {
final Intent gpsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
showDialog(gpsIntent, REQUEST_LOCATION_SETTINGS, getString(R.string.location_tracking_off));
} else {
final Intent internetIntent = new Intent(Settings.ACTION_WIFI_SETTINGS);
showDialog(internetIntent, REQUEST_WIFI_SETTINGS, getString(R.string.wireless_off));
}
}
@Override
protected void onResume() {
super.onResume();
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
SharedPreferences prefs = getPreferenceScreen().getSharedPreferences();
// Get preferences
Preference pref_check = findPreference(PREF_CHECK);
Preference pref_version = findPreference(PREF_VERSION);
// Set summaries
onSharedPreferenceChanged(prefs, PREF_ENABLED);
onSharedPreferenceChanged(prefs, PREF_TOAST);
onSharedPreferenceChanged(prefs, PREF_ALTITUDE);
onSharedPreferenceChanged(prefs, PREF_ACCURACY);
onSharedPreferenceChanged(prefs, PREF_TIMEOUT);
onSharedPreferenceChanged(prefs, PREF_KNOWN);
// Location settings
Intent locationSettingsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
if (getPackageManager().queryIntentActivities(locationSettingsIntent, 0).size() > 0)
pref_check.setIntent(locationSettingsIntent);
else
pref_check.setEnabled(false);
// Version
Intent playStoreIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getPackageName()));
if (getPackageManager().queryIntentActivities(playStoreIntent, 0).size() > 0)
pref_version.setIntent(playStoreIntent);
try {
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
pref_version.setSummary(
pInfo.versionName + "/" + pInfo.versionCode + "\n" +
getString(R.string.msg_geocoder) + " " +
getString(Geocoder.isPresent() ? R.string.msg_yes : R.string.msg_no));
} catch (PackageManager.NameNotFoundException ignored) {
}
}
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 = createBuilder(context, R.string.location_accuracy)
.setContentIntent(intentNotify)
.setAutoCancel(true)
.setSmallIcon(R.drawable.ic_location)
.setContentTitle(title)
.setContentText(info)
.setTicker(title);
manager.notify(NOTIFICATION_GPS_ID, builder.build());
}
/**
* Creates a new location settings intent.
*
* @param context the context
*/
public static Intent newLocationSettingsIntent(Context context) {
Intent intent = new Intent(useGoogleLocationSettings(context) ? ACTION_GOOGLE_LOCATION_SETTINGS
: Settings.ACTION_LOCATION_SOURCE_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return intent;
}
private void startMap(){
if( isLocationEnable() ){
mapFragment.getMapAsync( this );
}else{
Intent myIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS );
startActivity( myIntent );
}
}
/**
* Overload of {@link #turnOnLocationWithIntent_forOsServices(Activity, int)} if you don't care about result.
*
* @see com.idevicesinc.sweetblue.utils.BluetoothEnabler
*/
public final void turnOnLocationWithIntent_forOsServices(final Activity callingActivity)
{
final Intent enableLocationIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
callingActivity.startActivity(enableLocationIntent);
if( false == Utils.isMarshmallow() )
{
m_logger.w("You may use this method but since the phone is at " + Build.VERSION.SDK_INT + " and the requirement is "+Build.VERSION_CODES.M+", it is not necessary for scanning.");
}
}
public static void openGpsSettings(final Context context) {
final String action = Settings.ACTION_LOCATION_SOURCE_SETTINGS;
Intent intent = new Intent(action);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(intent);
}
/**
* Open location settings.
*/
private void enableLocationSettings() {
Intent settingsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(settingsIntent);
}
@OnClick(R.id.action_enable_location)
public void onEnableLocationClicked() {
final Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
private void clickCheckBox() {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
checkBox.setChecked(locationManager.isProviderEnabled("gps"));
}
/**
* Open system settings location services screen for turning on/off GPS
*/
public static Intent showLocationServices() {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
return intent;
}
/**
* Redirect user to enable GPS
*/
public void goToGpsSettings() {
Intent callGPSSettingIntent = new Intent(
Settings.ACTION_LOCATION_SOURCE_SETTINGS);
mContext.startActivity(callGPSSettingIntent);
}
static void openGPSSettings() {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
Activity activity = org.qtproject.qt5.android.QtNative.activity();
activity.startActivity(intent);
}
public static void requestLocationEnabling(@NonNull Activity activity) {
Log.d(TAG, "Requesting location enabling");
Intent locationSettings = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
activity.startActivity(locationSettings);
}
/**
* 打开Gps设置界面
*/
public static void openGpsSettings() {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
Utils.getApp().startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
private void openLocationSettings() {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
activity.startActivityForResult(intent, ENABLE_LOCATION_SERVICES_REQUEST);
}
@Override
public void startGpsIntent() {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivityForResult(intent, 202);
}
/**
* Returns an intent to launch Android Location Settings.
*/
public Intent getSystemLocationSettingsIntent() {
Intent i = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return i;
}
private void openLocationSettings() {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
activity.startActivityForResult(intent, ENABLE_LOCATION_SERVICES_REQUEST);
}