After moving the GPS setting dialog screen from the source below, check the GPS usage, and then click the back button
Click
intent = new Intent(this, CurrentLocatinActivity.class);
startActivity(intent);
I'd like to have the intents above re-run.
public class MainActivity extends AppCompatActivity {
String gpsEnabled;
Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
chkGpsService();
}
private boolean chkGpsService() {
//Confirmed that GPS is turned on.
gpsEnabled = android.provider.Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if (!(gpsEnabled.matches(".*gps.*") && gpsEnabled.matches(".*network.*"))) {
If //gps is not enabled,
new AlertDialog.Builder(this).setTitle ("GPS Settings").setMessage ("GPS is turned off). \nDo you want to enable GPS?").setPositiveButton("GPS On", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int which) {
//GPS setup screen displayed
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
}).setNegativeButton("Close", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
}).create().show();
}else if((gpsEnabled.matches(".*gps.*") && gpsEnabled.matches(".*network.*"))) {
Toast.makeText(getApplicationContext(), "Reading information.", Toast.LENGTH_LONG).show();
intent = new Intent (this, CurrentLocatinActivity.class); // Execute the int to display the current location screen.
startActivity(intent);
}
return false;
}
}
android restart-activity
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivityForResult(intent, 1);
Call to. For the rest, google on Activity Result.
© 2024 OneMinuteCode. All rights reserved.