默认权限始终被禁用。我需要在运行时要求它。如何在AppWidgetProvider
中请求运行时权限?
它不起作用:
int permissionCheck = ContextCompat.checkSelfPermission(context,
Manifest.permission.READ_CALENDAR);
if (permissionCheck != 0) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
ActivityCompat.requestPermissions((Activity) context,
new String[]{Manifest.permission.READ_CALENDAR},
1);
}
}
给出错误:
java.lang.ClassCastException: android.app.ReceiverRestrictedContext cannot be cast to android.app.Activity