我创建了一个广播接收器来挂钩日历EVENT_REMINDER并获取有关事件的信息
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bReceiver = new HealtDroidBroadcastReceiver();
IntentFilter inf = new IntentFilter("android.intent.action.EVENT_REMINDER");
inf.addDataScheme("content");
inf.addDataAuthority("com.android.calendar",null);
registerReceiver(bReceiver,inf);
}
Broadcastreceiver类中的:
public void onReceive(Context context, Intent intent) {
Uri uri = intent.getData();
String intentAction = intent.getAction();
ContentResolver cr = context.getContentResolver();
String sUri = uri.toString();
Uri alertUri = Uri.parse(sUri);
Cursor alertCursor = cr.query(alertUri, ALERT_PROJECTION,
null /* selection */, null, null /* sort order */);
但cr.query:
时出错未知网址内容://com.android.calendar/1373401980000
答案 0 :(得分:5)
附加的ID不是eventID,而是alarmTime。 了解如何在此处创建警报广播: scheduleAlarm()
您可以使用以下方式获取alarmTime:
String alarmTime = uri.getLastPathSegment();
然后,您可以使用它来查询CalendarAlerts:
String[] projection = new String[] {
CalendarAlerts.EVENT_ID
};
String selection = CalendarContract.CalendarAlerts.ALARM_TIME + "=?";
Cursor c = cr.query(CalendarContract.CalendarAlerts.CONTENT_URI_BY_INSTANCE,
projection,
selection,
new String[] {alarmTime},
null);
...