如何设置Android的多个提醒 [英] how to set multiple reminders in Android

查看:158
本文介绍了如何设置Android的多个提醒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好朋友需要帮助!

我工作在Android上,在我的应用程序有同时设置多个提醒的要求。事情是这样的。

 的for(int i = 0; I< N;我++)
 {
     // code设置提醒
 }

目前我有以下code,但只有在一次一个提醒工作正常。

  StringTokenizer的ST =新的StringTokenizer(strDateForReminder, - );
             cal.set(Calendar.DAY_OF_MONTH,的Integer.parseInt(st.nextToken()));
             cal.set(的Calendar.MONTH,的Integer.parseInt(st.nextToken()) - 1);
             cal.set(Calendar.YEAR,的Integer.parseInt(st.nextToken()));             字符串strTime = textView.getText()的toString()修剪()。
            // Toast.makeText(getApplicationContext(),strTime =+ strTime,Toast.LENGTH_LONG).show();             的String [] = strTimeArray strTime.split(getResources()的getString(R.string.delimiter));
             串[] strFirstTime = strTimeArray [0] .split(:);
             cal.set(Calendar.HOUR_OF_DAY,的Integer.parseInt(strFirstTime [0]));
             cal.set(Calendar.MINUTE,的Integer.parseInt(strFirstTime [1]));
             cal.set(Calendar.SECOND,00);             意向意图=新意图(Intent.ACTION_EDIT);
             intent.setType(vnd.android.cursor.item /事件);
             intent.putExtra(BEGINTIME,cal.getTimeInMillis());
             intent.putExtra(结束时间,cal.getTimeInMillis()+ 90 * 60 * 1000);
             intent.putExtra(称号,提醒);
             startActivity(意向);

请帮助。在此先感谢!


解决方案

如果我理解正确,使用的活动你的方法只允许您一次添加一个事件,因为用户必须与设备,以确认它进行交互。你需要的是新的 CalendarContract 在4.0中引入的。

Android的食谱:


  

基于ContentProvider的法可能是,如果你不希望用户必须与一个日历应用程序进行交互preferable。在升级Froyo和姜饼和蜂窝版本中,你必须知道的名称来使用,为你想与之交互的各个领域。因为它是官方支持:我们没有这种方法,但你可以通过我们的撰稿人吉姆·布莱克在的 http://jimblackler.net/blog/?p=151


  
  

与Ice Cream Sandwich的有效(的Andr​​oid 4.0,API等级14),新CalendarContract类持有,在各种嵌套类的,所需的全部常量,使便携式日历应用程序。这显示直接插入的日历事件到用户的第一个日历(使用id为1);显然应该有一个下拉在实际应用中列出用户的日历。


 公共无效的addEvent(上下文CTX,弦乐标题,日历开始,日历结束){
    Log.d(TAGAddUsingContentProvider.addEvent());    TextView的calendarList =
        (TextView中)((活动)CTX).findViewById(R.id.calendarList);    ContentResolver的ContentResolver的= ctx.getContentResolver();    ContentValues​​ calEvent =新ContentValues​​();
    calEvent.put(CalendarContract.Events.CALENDAR_ID,1); // XXX拾取)
    calEvent.put(CalendarContract.Events.TITLE,职称);
    calEvent.put(CalendarContract.Events.DTSTART,start.getTimeInMillis());
    calEvent.put(CalendarContract.Events.DTEND,end.getTimeInMillis());
    calEvent.put(CalendarContract.Events.EVENT_TIMEZONE,加拿大/东航);
    URI URI = contentResolver.insert(CalendarContract.Events.CONTENT_URI,calEvent);    //返回乌里包含内容猎犬的URI
    //新插入的事件,包括它的id
    INT ID =的Integer.parseInt(uri.getLastPathSegment());
    Toast.makeText(CTX,创建的日历事件+ ID,
        Toast.LENGTH_SHORT).show();
}

Hello Friends Need Help!

I'm working on Android, In my application there is a requirement to set multiple reminders at a time. Something like this

 for( int i = 0; i < n; i++)
 {
     // Code to set Reminder
 }

Currently I have following code, but that works fine only for one reminder at a time.

 StringTokenizer st=new StringTokenizer(strDateForReminder, "-");
             cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(st.nextToken()));
             cal.set(Calendar.MONTH, Integer.parseInt(st.nextToken())-1);
             cal.set(Calendar.YEAR, Integer.parseInt(st.nextToken()));

             String strTime= textView.getText().toString().trim();
            // Toast.makeText(getApplicationContext(), "strTime= "+strTime, Toast.LENGTH_LONG).show();

             String[] strTimeArray = strTime.split(getResources().getString(R.string.delimiter));
             String[] strFirstTime=strTimeArray[0].split(":");
             cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(strFirstTime[0]));
             cal.set(Calendar.MINUTE, Integer.parseInt(strFirstTime[1]));
             cal.set(Calendar.SECOND, 00);

             Intent intent = new Intent(Intent.ACTION_EDIT);
             intent.setType("vnd.android.cursor.item/event");
             intent.putExtra("beginTime", cal.getTimeInMillis());
             intent.putExtra("endTime", cal.getTimeInMillis()+90*60*1000);
             intent.putExtra("title", "Reminder");
             startActivity(intent);

Please Help. Thanks in Advance!

解决方案

If I understand correctly, your approach using an activity only allows you to add one event at a time because the user has to interact with the device to confirm it. What you want is the new CalendarContract introduced in 4.0.

From Android Cookbook:

The ContentProvider-based method may be preferable if you do not want the user to have to interact with a calendaring application. In Froyo and Gingerbread and Honeycomb releases, you had to "know" the names to use for the various fields you wanted to interact with. We do not cover this method as it is officially unsupported, but you can find a good article on the web by our contributor Jim Blacker, at http://jimblackler.net/blog/?p=151.

Effective with Ice Cream Sandwich (Android 4, API level 14), the new CalendarContract class holds, in a variety of nested classes, all the constants needed to make a portable calendar application. This is shown inserting a Calendar Event directly into the user's first Calendar (using id 1); obviously there should be a drop-down listing the user's calendars in a real application.

public void addEvent(Context ctx, String title, Calendar start, Calendar end) {
    Log.d(TAG, "AddUsingContentProvider.addEvent()");

    TextView calendarList = 
        (TextView) ((Activity) ctx).findViewById(R.id.calendarList);

    ContentResolver contentResolver = ctx.getContentResolver();

    ContentValues calEvent = new ContentValues();
    calEvent.put(CalendarContract.Events.CALENDAR_ID, 1); // XXX pick)
    calEvent.put(CalendarContract.Events.TITLE, title);
    calEvent.put(CalendarContract.Events.DTSTART, start.getTimeInMillis());
    calEvent.put(CalendarContract.Events.DTEND, end.getTimeInMillis());
    calEvent.put(CalendarContract.Events.EVENT_TIMEZONE, "Canada/Eastern");
    Uri uri = contentResolver.insert(CalendarContract.Events.CONTENT_URI, calEvent);

    // The returned Uri contains the content-retriever URI for 
    // the newly-inserted event, including its id
    int id = Integer.parseInt(uri.getLastPathSegment());
    Toast.makeText(ctx, "Created Calendar Event " + id,
        Toast.LENGTH_SHORT).show();
}

这篇关于如何设置Android的多个提醒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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