Android Calendar illegalArgumentException

时间:2015-10-23 11:55:42

标签: android xamarin xamarin.forms

我有以下错误消息

illegalArgumentException:只有同步适配器可以写入ownerAccount 使用时

**this line:---** values.Put(CalendarContract.Calendars.InterfaceConsts.OwnerAccount, 
AccountOwner);
values.Put(CalendarContract.Calendars.InterfaceConsts.AccountName, AccountName);
values.Put(CalendarContract.Calendars.InterfaceConsts.Id, CalendarID);
values.Put(CalendarContract.Calendars.InterfaceConsts.Visible, 1);
values.Put(CalendarContract.Calendars.InterfaceConsts.SyncEvents, 1);
cr.Insert(CalendarContract.Calendars.ContentUri, values);

这可能如何尝试每个例子。 我从OnActivityResult中的AccountPicker获取帐户名称,如

protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
{
    base.OnActivityResult(requestCode, resultCode, data);   

    if(requestCode == MyClass.RequestCode && resultCode == Result.Ok)
    {
        GSDEvents.AccountName = data.GetStringExtra(AccountManager.KeyAccountName);
        DependencyService.Get<MyClass>().AddCalendar(8, GSDFuncties.ApplicationName, MyClass.AccountName, MyClass.AccountName);
        Toast.MakeText(this, GSDEvents.AccountName, ToastLength.Long).Show();
    }


}

1 个答案:

答案 0 :(得分:0)

使用以下方式解决:

 calUri = calUri.BuildUpon()
    .AppendQueryParameter(CalendarContract.CallerIsSyncadapter, "true")
    .AppendQueryParameter(CalendarContract.Calendars.InterfaceConsts.AccountName, AccountName)
    .AppendQueryParameter(CalendarContract.Calendars.InterfaceConsts.AccountType, CalendarContract.AccountTypeLocal)
    .Build();

cr.Insert(calUri, values);