我试图让我的应用程序使用我设置的一些数据自动为日历设置一个事件。
@SuppressLint({ "NewApi", "ShowToast" })
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create a new calendar view
CalendarView calView = (CalendarView) findViewById(R.id.calendar);
calView.setOnDateChangeListener(new OnDateChangeListener() {
public void onSelectedDayChange(CalendarView view, int year, int month,
int dayOfMonth) {
//Toast.makeText(getApplicationContext(), "" + dayOfMonth, 0).show();
// Call built in calendar
Calendar cal = new GregorianCalendar();
cal.set(year, month, dayOfMonth); // sets the date picker to the clicked date
cal.add(Calendar.MONTH, 0); // 0 for current month
Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setData(Events.CONTENT_URI);
intent.putExtra(Events.TITLE, "App Event Test");
intent.putExtra(Events.EVENT_LOCATION, "At House");
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, cal.getTime().getTime());
intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, cal.getTime().getTime() + 3600000); //3600000 for an hour //600000 for 10 minutes
intent.putExtra(Intent.EXTRA_EMAIL, "eden@gurango.com, elliot@gurango.com");
Toast.makeText(getApplicationContext(), month +"-"+ dayOfMonth +"-"+ year, 0).show();
startActivity(intent);
}
});
}
}
当然这里的问题是它仍然会提示用户是“取消”还是“完成”并在他的日历上设置这个事件。有人可以告诉我有关如何自动设置事件的链接或代码片段吗?