Runtime Permissions: no permission immediately after granting
<p>I'm trying to get a storage permission in Marshmallow. Everything seems to work great and I can grant or deny a permission. </p>

<pre><code>private static final int REQUEST_STORAGE = 1;

// request storage permission
private void requestStoragePermission() {
    String[] permissions = new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE };
    if (!hasStoragePermission()) {
        Log.e(TAG, "No storage permission at the moment. Requesting...");
        ActivityCompat.requestPermissions(this, permissions, REQUEST_STORAGE);
    } else
        Log.e(TAG, "We already have storage permission. Yay!");
}

// check is storage permission granted
private boolean hasStoragePermission() {
    String storagePermission = Manifest.permission.WRITE_EXTERNAL_STORAGE;
    int hasPermission = ContextCompat.checkSelfPermission(this, storagePermission);
    return (hasPermission == PackageManager.PERMISSION_GRANTED);
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    switch (requestCode) {
        case REQUEST_STORAGE:
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                Log.e(TAG, "Storage permission granted");
            } else {
                Log.e(TAG, "Storage permission denied");
                Toast.makeText(getApplicationContext(), getString(R.string.no_storage_permission), Toast.LENGTH_SHORT).show();
            }
            break;
    }
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
</code></pre>

<p>However the problem is here. When I'm using this feature for the first time, <code>hasStoragePermission()</code> is always false, even after granting the permission. When the permission wasn't granted before I have to use the context menu twice to be able to do what I want. It's unacceptable.</p>

<pre><code>// some code...
// even more code...

@Override
public boolean onContextItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case ID_CONTEXT_MENU_SAVE_IMAGE:
            // in order to save anything we need storage permission
            requestStoragePermission();
            Log.e("SomeActivity", "storagePermissionGranted: " + hasStoragePermission());
            if (!hasStoragePermission())
                return false;
            saveImageToDisk(mPendingImageUrlToSave);
            break;
    }
    return super.onContextItemSelected(item);
}
</code></pre>

<p>Is there any known bug in Android Marshmallow which could cause it? The code seems to be ok because in fact I can grant / deny storage permission. I want to have it immediately though.</p>