How to check user permission is allow or not in android

Android tutorial

Android How to check user permission is allow or not in android is to allow or not marshmallow and higher and show a dialog when permission is not allowed. In this Android tutorial, I am sharing How permission can be checked at runtime without throwing SecurityException? marshmallow and higher version and show a dialog to allow user permission.

Step 1: First one to  Start Android Studio

Step 2 :  Seconds step to Create a New Project Project Click On ==>  File  ==>NEW ==> New Project And Create Activity in your project 

And add permission in manifests file how you required like these:- 


<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="" />
<uses-feature android:name="" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="" />
<uses-permission android:name="" />

Add these code where you can check user permission in any activity . for  add these code in your java class

public class LogIn extends AppCompatActivity {
    int PERMISSION_ALL = 1;
    String[] PERMISSIONS = {android.Manifest.permission.READ_EXTERNAL_STORAGE, android.Manifest.permission.WRITE_EXTERNAL_STORAGE,  android.Manifest.permission.CHANGE_NETWORK_STATE, android.Manifest.permission.CAMERA,android.Manifest.permission.ACCESS_FINE_LOCATION};

    protected void onCreate(Bundle savedInstanceState) {

        if(!hasPermissions(this, PERMISSIONS)){
            ActivityCompat.requestPermissions(this, PERMISSIONS, PERMISSION_ALL);
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP){
        } else{
            // do something for phones running an SDK before lollipop


public static boolean hasPermissions(Context context, String... permissions) {
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context != null && permissions != null) {
        for (String permission : permissions) {
            if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
                return false;
    return true;
} }