在更改日历事件提醒变化的情况下ID,而不是提醒ID [英] Changing a reminder on a calendar event changes the event id, not reminder id

查看:336
本文介绍了在更改日历事件提醒变化的情况下ID,而不是提醒ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写一些code,可以告诉我们,如果对事件的提醒被改变(或者是添加或删除),但我发现了一个奇怪的现象。取而代之的是提醒被删除或更改,这似乎已经被删除的情况下,重新加入!是我的code不正确的?或者,这是什么是真正发生的?

要测试这一点,你需要:


  1. 创建一个提醒事件


  2. 点击该按钮同步T后模拟器


  3. 在该事件中删除提醒


  4. 等到那变化同步到你的模拟器,然后再次单击该按钮


JAVA code

 包com.example.remindertest;进口java.text.DateFormat中;
进口java.text.SimpleDateFormat的;
进口的java.util.Calendar;进口android.app.Activity;
进口android.content.ContentResolver;
进口android.content.ContentUris;
进口android.database.Cursor;
进口android.net.Uri;
进口android.provider.CalendarContract.CalendarAlerts;
进口android.provider.CalendarContract.Events;
进口android.provider.CalendarContract.Instances;
进口android.provider.CalendarContract.Reminders;
进口android.util.Log;
进口android.view.View;公共类ReminderActivity扩展活动
{
    最终静态公共字符串标记=ReminderActivity;    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);        //添加按钮
        的setContentView(R.layout.reminder_activity);
        Log.d(TAG,启动);
    }    公共无效的onClick(视图v)
    {
        光标光标= getContentResolver()查询(
            Reminders.CONTENT_URI,
            NULL,NULL,NULL,NULL
        );        字符串str =;        / *
        *有些蹩脚code测试此
        * /
        而(cursor.moveToNext())
        {
            INT事件ID = cursor.getInt(cursor.getColumnIndex(Reminders.EVENT_ID));
            光标eCursor = getContentResolver()查询(
                Events.CONTENT_URI,
                新的String [] {Events._ID,Events.TITLE},
                _id =?,新的String [] {+ EVENTID}(字符串)NULL);            eCu​​rsor.moveToNext();
            字符串title = eCursor.getString(eCursor.getColumnIndex(Events.TITLE));            STR + = EVENTID +=+标题+=+
                cursor.getInt(cursor.getColumnIndex(Reminders._ID))+=+
                cursor.getInt(cursor.getColumnIndex(Reminders.METHOD))+=+
                cursor.getLong(cursor.getColumnIndex(Reminders.MINUTES))+\\ n;
        }        Log.d(TAG,STR);
    }
}

布局XML

 <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  的xmlns:工具=htt​​p://schemas.android.com/tool​​s
  机器人:layout_width =match_parent
  机器人:layout_height =match_parent
  工具:上下文=。ReminderActivity><按钮
    机器人:ID =@ + ID /按钮1
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentTop =真
    机器人:layout_centerHorizo​​ntal =真
    机器人:layout_marginTop =98dp
    安卓的onClick =的onClick
    机器人:文字=按钮/>< / RelativeLayout的>

清单XML

 <?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  包=com.example.remindertest
  安卓版code =1
  机器人:=的versionName1.0><用途-SDK
    安卓的minSdkVersion =14
    机器人:targetSdkVersion =17/><使用许可权的android:NAME =android.permission.READ_CALENDAR/>
<使用许可权的android:NAME =android.permission.WRITE_CALENDAR/><应用
    机器人:allowBackup =真
    机器人:图标=@绘制/ ic_launcher
    机器人:标签=@字符串/ APP_NAME
    机器人:主题=@风格/ AppTheme>
    <活动
    机器人:名字=com.example.remindertest.ReminderActivity
    机器人:标签=@字符串/ APP_NAME>
    &所述;意图滤光器>
        <作用机器人:名字=android.intent.action.MAIN/>        <类机器人:名字=android.intent.category.LAUNCHER/>
    &所述; /意图滤光器>
    < /活性GT;
< /用途>< /清单>


解决方案

没有,你的code是正确的。完全相同发生在我的6个设备 - 事件改变了它的ID(可能是重建)当您编辑它。顺便说一句,这也发生在您更改事件的时间,名称,位置或任何其他细节 - 不只是提醒。搞笑的是,它并不总是发生 - 只是有时。但一般2-3编辑事件都足以模仿这种行为。

我不太知道为什么事件的频繁改变他们的ID,但在此基础上,我会说的原因,该事件的id不应该被用来作为唯一标识符。

I am trying to write some code that can tell if the reminders on an event were changed (either one added or removed) but I'm getting a weird occurrence. Instead of the reminder being removed or altered, it appears the event is being removed and re-added! Is my code incorrect? Or is this what's really occurring?

To test this, you'll need to:

  1. create an event with a reminder

  2. click the button after that syncs t your emulator

  3. Remove the reminder on the event

  4. Wait till that change syncs to your emulator and then click the button again

JAVA CODE

package com.example.remindertest;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.database.Cursor;
import android.net.Uri;
import android.provider.CalendarContract.CalendarAlerts;
import android.provider.CalendarContract.Events;
import android.provider.CalendarContract.Instances;
import android.provider.CalendarContract.Reminders;
import android.util.Log;
import android.view.View;

public class ReminderActivity extends Activity
{
    final static public String TAG = "ReminderActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //Add button
        setContentView(R.layout.reminder_activity);
        Log.d(TAG, "Started");
    }

    public void onClick(View v)
    {
        Cursor cursor = getContentResolver().query(
            Reminders.CONTENT_URI,
            null, null, null, null
        );

        String str = "";

        /*
        * Some crappy code to test this
        */
        while ( cursor.moveToNext())
        {
            int eventId = cursor.getInt(cursor.getColumnIndex(Reminders.EVENT_ID));
            Cursor eCursor = getContentResolver().query(
                Events.CONTENT_URI,
                new String[] { Events._ID, Events.TITLE },
                "_id = ?", new String[] {"" + eventId}, ( String ) null);

            eCursor.moveToNext();
            String title = eCursor.getString(eCursor.getColumnIndex(Events.TITLE));

            str += eventId + " = " + title + " = " +
                cursor.getInt(cursor.getColumnIndex(Reminders._ID)) + " = " +
                cursor.getInt(cursor.getColumnIndex(Reminders.METHOD)) + " = " +
                cursor.getLong(cursor.getColumnIndex(Reminders.MINUTES)) + "\n";
        }

        Log.d(TAG, str);
    }
}

LAYOUT XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".ReminderActivity" >

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="98dp"
    android:onClick="onClick"
    android:text="Button" />

</RelativeLayout>

MANIFEST XML

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.remindertest"
  android:versionCode="1"
  android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="17" />

<uses-permission android:name="android.permission.READ_CALENDAR"/>
<uses-permission android:name="android.permission.WRITE_CALENDAR"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
    android:name="com.example.remindertest.ReminderActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    </activity>
</application>

</manifest>

解决方案

No, your code is correct. Exactly same happens on my 6 devices - event changes it's id (probably is recreated) when you edit it. Btw, it happens also when you change event's time, title, location or any other details - not just reminder. Funny is, that it doesn't always happen - just sometimes. But usually 2-3 edits of event are enough to simulate this behavior.

I do not quite know the reason why event's frequently changes their ids, but based on this I would say, that event's id shouldn't be used as unique identifier.

这篇关于在更改日历事件提醒变化的情况下ID,而不是提醒ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆