In Android M, you need to ask for permission, which in PermissionModel is defined as dangerous for the user, before you start using it every time, it is as such:
private boolean mayRequestLocation() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return true; } if (checkSelfPermission(ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { return true; } if (shouldShowRequestPermissionRationale(ACCESS_FINE_LOCATION)) { Snackbar.make(mView, R.string.permission_rationale, Snackbar.LENGTH_INDEFINITE) .setAction(android.R.string.ok, new View.OnClickListener() { @Override @TargetApi(Build.VERSION_CODES.M) public void onClick(View v) { requestPermissions(new String[]{ACCESS_FINE_LOCATION}, REQUEST_FINE_LOCATION); } }); } else { requestPermissions(new String[]{ACCESS_FINE_LOCATION}, REQUEST_FINE_LOCATION); } return false; }
Add this to your activity:
private static final int REQUEST_FINE_LOCATION=0
and load it at runtime:
loadPermissions(Manifest.permission.ACCESS_FINE_LOCATION,REQUEST_FINE_LOCATION);
To evaluate the results of your permission request, you can override the onRequestPermissionsResult method:
@Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { switch (requestCode) { case REQUEST_FINE_LOCATION: {
source share