I have an app that needs write calendar now considered "critical" so I following the guidelines HERE I have added in Activity onCreate this cote
private static final int REQUEST_WRITE_CALENDAR = 1453;
...
boolean hasPermission = (ContextCompat.checkSelfPermission(activity,
Manifest.permission.WRITE_CALENDAR) == PackageManager.PERMISSION_GRANTED);
if (!hasPermission) {
ActivityCompat.requestPermissions(parentActivity,
new String[]{Manifest.permission.WRITE_CALENDAR},
REQUEST_WRITE_CALENDAR);
}
But this doesn't show any dialog.
In addition seems I should ad also this code block to handle response
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode)
{
case REQUEST_WRITE_STORAGE: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED)
{
//reload my activity with permission granted or use the features what required the permission
} else
{
Toast.makeText(parentActivity, "The app was not allowed to write to your calendar.", Toast.LENGTH_LONG).show();
}
}
}
}
The Android Target SDK is 23 and is correct. So the cause of the problem is different from that proposed in possible duplicate question.