PermissionUtil:권한 도구 클래스
1075 단어 android-util
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Build;
import java.util.ArrayList;
/**
* Android23
*/
public class PermissionUtil {
/**
*
*
* @param activity
*/
public static void checkPermission(Activity activity, String... permissions) {
if (Build.VERSION.SDK_INT >= 23) {
int requestCode = 0;
ArrayList permissionsInfo = new ArrayList();
for (String item : permissions) {
int check = activity.checkSelfPermission(item);
if (check != PackageManager.PERMISSION_GRANTED) {
requestCode |= 1 << 0;
permissionsInfo.add(item);
}
}
if (requestCode > 0) {
String[] permission = new String[permissionsInfo.size()];
activity.requestPermissions(permissionsInfo.toArray(permission), requestCode);
}
}
}
}