import android.Manifest; import android.app.Activity; import android.content.pm.PackageManager; import android.os.Build;
import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat;
import java.util.ArrayList; import java.util.List;
public class Permission { private String[] permission = { Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.INTERNET, Manifest.permission.ACCESS_NETWORK_STATE, Manifest.permission.ACCESS_WIFI_STATE, Manifest.permission.READ_PHONE_STATE, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.INTERACT_ACROSS_PROFILES, Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO };
private List<String> permissionlist = new ArrayList<>();
private int REQUSET_CODE = 1000;
public void checkpermission(Activity activity){
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.M){
for (int i = 0; i < permission.length; i++) {
if (ContextCompat.checkSelfPermission(activity,permission[i]) != PackageManager.PERMISSION_GRANTED){
permissionlist.add(permission[i]);
}
}
if (permissionlist.size()>0){
requestPermission(activity);
}
}
}
private void requestPermission(Activity activity){
ActivityCompat.requestPermissions(activity,permissionlist.toArray(new String[permissionlist.size()]),REQUSET_CODE);
}
}
|