int permission1 = PermissionChecker.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION); int permission2 = PermissionChecker.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION); int ddd = PackageManager.PERMISSION_GRANTED; if (ContextCompat.checkSelfPermission(getBaseContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.shouldShowRequestPermissionRationale(SignInActivity.this, android.Manifest.permission.ACCESS_COARSE_LOCATION)) { /* do nothing*/ } else { ActivityCompat.requestPermissions(SignInActivity.this, new String[]{android.Manifest.permission.ACCESS_COARSE_LOCATION, android.Manifest.permission.ACCESS_FINE_LOCATION}, GET_MY_PERMISSION); } } else if ((permission1 == PackageManager.PERMISSION_GRANTED) || permission2 == PackageManager.PERMISSION_GRANTED) { // permission not granted, you decide what to do Toast.makeText(this, getResources().getString(R.string.on_location), Toast.LENGTH_SHORT).show(); Intent myIntent = new Intent(Settings.ACTION_SETTINGS); startActivity(myIntent); } else { frame = findViewById(R.id.maps_frame_content); frame.setVisibility(View.VISIBLE); Fragment mFragment = new ShowMeOnMap(true, frame); FragmentManager mFragmentManager = getSupportFragmentManager(); mFragmentManager.beginTransaction().replace(R.id.maps_frame_content, mFragment).commit(); } 

I use this code to ask permission on the phones.

The first if for Runtime permission second for devices on android 5.1 and less.

The problem is that I can not correctly determine on android 5.1.1 and less whether geolocation is enabled or not

  • Before android 6, permissions are specified in the manifest, specify the necessary permissions in the manifest, and in the class, make a condition if android user 6 or higher to request permissions - McDaggen
  • Thanks, I see - Abdugani_T

1 answer 1

Before android 6, the permissions are specified in the manifest, specify the necessary permissions in the manifest, and in the class, make a condition if the android of the user is 6 or higher, so that you can request permission @McDaggen