Created
February 21, 2022 08:29
-
-
Save hardikhari96/ff0378829f3a1fe3471a83aa6e92ab7f to your computer and use it in GitHub Desktop.
get Permission for android app,
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 java.util.List; | |
import android.content.pm.PackageManager; | |
import androidx.core.app.ActivityCompat; | |
import java.util.ArrayList; | |
// get all permission | |
private void checkPermissions() { | |
String[] permissions = new String[]{ | |
Manifest.permission.READ_EXTERNAL_STORAGE, | |
Manifest.permission.ACCESS_NOTIFICATION_POLICY, | |
Manifest.permission.CAMERA, | |
}; | |
int result; | |
List<String> listPermissionsNeeded = new ArrayList<>(); | |
for (String p : permissions) { | |
result = ContextCompat.checkSelfPermission(this, p); | |
if (result != PackageManager.PERMISSION_GRANTED) { | |
listPermissionsNeeded.add(p); | |
} | |
} | |
if (!listPermissionsNeeded.isEmpty()) { | |
ActivityCompat.requestPermissions(this, listPermissionsNeeded.toArray(new String[listPermissionsNeeded.size()]), 100); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment