您好需要帮助的 friend !
我在 Android 上工作,在我的应用程序中需要一次设置多个提醒。像这样
for( int i = 0; i < n; i++)
{
// Code to set Reminder
}
目前我有以下代码,但一次只能用于一个提醒。
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);
请帮助。提前致谢!
最佳答案
如果我理解正确,您使用 Activity 的方法只允许您一次添加一个事件,因为用户必须与设备交互以确认它。你要的是新款CalendarContract
在 4.0 中引入。
来自 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 - 如何在Android中设置多个提醒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17719696/