Last active
April 26, 2021 12:10
-
-
Save oluwabajio/8c6c712c296cba63250a05339d912179 to your computer and use it in GitHub Desktop.
Android Permission Helper Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.Manifest; | |
import android.app.Activity; | |
import android.content.Context; | |
import android.content.pm.PackageManager; | |
import androidx.core.app.ActivityCompat; | |
import androidx.core.content.ContextCompat; | |
public class PermissionHelper { | |
private final static int PERMISSIONCODE = 100; | |
public static boolean checkPermissions(Context context){ | |
boolean result = ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA) | |
== PackageManager.PERMISSION_GRANTED | |
&& ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) | |
== PackageManager.PERMISSION_GRANTED | |
&& ContextCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE) | |
== PackageManager.PERMISSION_GRANTED; | |
return result; | |
} | |
public static void requestPermissions(Activity activity){ | |
ActivityCompat.requestPermissions(activity, | |
new String[]{Manifest.permission.CAMERA, | |
Manifest.permission.WRITE_EXTERNAL_STORAGE, | |
Manifest.permission.READ_EXTERNAL_STORAGE}, PERMISSIONCODE); | |
} | |
public static boolean checkRequest(int requestCode,int[] grantResults){ | |
boolean result = false; | |
result = requestCode == PERMISSIONCODE | |
&& grantResults.length == 3 | |
&& grantResults[0] == PackageManager.PERMISSION_GRANTED | |
&& grantResults[1] == PackageManager.PERMISSION_GRANTED | |
&& grantResults[2] == PackageManager.PERMISSION_GRANTED; | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment