我想检查是否允许来自静态类的存储权限。我没有活动对象,因为静态类扩展了Application。 我使用了以下活动代码
checkSelfPermission(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE};
但是从静态类中它会抛出错误,因为它是一个非静态方法
答案 0 :(得分:0)
public class Temp {
public static void requestPermission(Activity act) {
int status = ActivityCompat.checkSelfPermission(act, Manifest.permission.READ_EXTERNAL_STORAGE);
if (status != PackageManager.PERMISSION_GRANTED) {
Logger.e("permission not granted");
ActivityCompat.requestPermissions(act, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 4322);
}
}
}
呼叫
Temp.requestPermission(activity/context);