onRequestPermissionsResult never gets called in fragment : <p>Below code is working fine in Activity but I <strong>cannot make it work inside a Fragment.</strong></p>

<p>The <code>onRequestPermissionsResult</code> is never gets called.</p>

<p>There is a <code>requestPermissions</code> function in API level 23 (Android 6.0) but I need to make it work on lower levels like API level 21 (Android 5.0) so unfortunetely I cannot use that. <code>ActivityCompat.requestPermissions</code> just simply not calls <code>onRequestPermissionsResult</code>.</p>

<p>Any suggestion?</p>

<pre><code>public class MyFragment extends Fragment {

final int REQUEST_CODE = 120;

@Override
public View onCreateView(LayoutInflater infl, ViewGroup cont, Bundle bundle) {

    if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
        Log.i("LOG", "Asking for permission right now..");

        ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.READ_CONTACTS}, REQUEST_CODE);


        //This is working but needs API level 23 (Android 6.0) - How to make this work on Android 5.0?
        //requestPermissions( new String[]{Manifest.permission.READ_CONTACTS}, REQUEST_CODE);
    }

    return super.onCreateView(infl, cont, bundle);
}

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {

    Log.i("LOG", "onRequestPermissionsResult!");

    if (requestCode == REQUEST_CODE) {
        if (grantResults.length &gt; 0 &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            Log.i("LOG", "GRANTED");
            Toast.makeText(getActivity(), "GRANTED,", Toast.LENGTH_LONG).show();

        } else {
            Log.i("LOG", "REFUSED");
            Toast.makeText(getActivity(), "REFUSED,", Toast.LENGTH_LONG).show();
        }
    }
}
}
</code></pre>
