and*_*per 5 android android-intent android-calendar android-securityexception
In order to go to the calendar at a specific time, we use this (based on this link) :
@Nullable
public static Intent prepareIntentForCalendar(final Context context, final Date date) {
Intent intent = null;
final Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
builder.appendPath("time");
ContentUris.appendId(builder, date.getTime());
intent = new Intent(Intent.ACTION_VIEW).setData(builder.build());
final PackageManager pm = context.getPackageManager();
final ResolveInfo resolveActivity = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY
| PackageManager.GET_RESOLVED_FILTER);
if (resolveActivity == null)
return null;
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY
| Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
return intent;
}
Run Code Online (Sandbox Code Playgroud)
Only if it's not null, we allow to use the Intent.
Recently I've got a weird exception about this. It goes as such:
Fatal Exception: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.VIEW dat=content://com.android.calendar/time/-11518765200000 flg=0x58080000 cmp=com.google.android.gm/.browse.TrampolineActivity } from ProcessRecord{fb2ca43 25597:.../u0a127} (pid=25597, uid=10127) requires com.google.android.gm.permission.READ_GMAIL
at android.os.Parcel.readException(Parcel.java:1945)
at android.os.Parcel.readException(Parcel.java:1891)
at android.app.IActivityManager$Stub$Proxy.startActivity(IActivityManager.java:4373)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1631)
at android.app.Activity.startActivityForResult(Activity.java:4762)
at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:68)
at android.app.Activity.startActivityForResult(Activity.java:4702)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:751)
at android.app.Activity.startActivity(Activity.java:5123)
at android.app.Activity.startActivity(Activity.java:5091)
at
...
Run Code Online (Sandbox Code Playgroud)
The docs don't say anything about permission requirement. In fact, it says the opposite, if all you use is an Intent:
Your application doesn't need permissions to read and write calendar data. It can instead use intents supported by Android's Calendar application to hand off read and write operations to that application. The following table lists the intents supported by the Calendar Provider:
Searching the Internet, I didn't get even one good clue about what's going on.
Only thing I know is that it occurs on various devices and various Android versions, as reported on Crashlytics:
For now, I've also reported about this here, because I believe this crash shouldn't occur.
| 归档时间: |
|
| 查看次数: |
389 次 |
| 最近记录: |