我已在清单和已安装的应用程序中授予了READ_CALENDAR和WRITE_CALENDAR权限,并已授予了Calendar运行时权限,并从应用程序的设置中验证了这一点。
但是,即使在某些设备上,我仍然需要android.permission.READ_CALENDAR或android.permission.WRITE_CALENDAR 错误!疯了吧!这是我的日志:
Fatal Exception: java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:353)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
Caused by java.lang.SecurityException: Permission Denial: opening provider com.android.providers.calendar.CalendarProvider2 from ProcessRecord{76fdbc0 21351:com.app.byday/u0a166} (pid=21351, uid=10166) requires android.permission.READ_CALENDAR or android.permission.WRITE_CALENDAR
at android.os.Parcel.readException(Parcel.java:1943)
at android.os.Parcel.readException(Parcel.java:1889)
at android.app.IActivityManager$Stub$Proxy.getContentProvider(IActivityManager.java:4885)
at android.app.ActivityThread.acquireProvider(ActivityThread.java:6019)
at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2525)
at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1791)
at android.content.ContentResolver.query(ContentResolver.java:749)
at android.content.ContentResolver.query(ContentResolver.java:715)
at android.content.CursorLoader.loadInBackground(CursorLoader.java:64)
at android.content.CursorLoader.loadInBackground(CursorLoader.java:54)
at android.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:315)
at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:69)
at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:64)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
其他信息:我已经在我的应用程序中集成了Etar-AOSP日历应用程序。
答案 0 :(得分:0)
那些需要运行时权限,而不仅仅是对任何现代版本的Android的清单权限。
答案 1 :(得分:0)
首先,您需要向manifest.xml添加权限。对于日历,您需要添加此权限
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
在运行时,您需要再次请求许可。因此,您可以创建一些函数来检查它。为您的回调声明一个vble
final int callbackId = 42;
并调用您的函数以检查权限
checkPermission(callbackId, Manifest.permission.READ_CALENDAR, Manifest.permission.WRITE_CALENDAR);
这是声明的功能:
private void checkPermission(int callbackId, String... permissionsId) {
boolean permissions = true;
for (String p : permissionsId) {
permissions = permissions && ContextCompat.checkSelfPermission(this, p) == PERMISSION_GRANTED;
}
if (!permissions)
ActivityCompat.requestPermissions(this, permissionsId, callbackId);
}