0
嗨我已經創建了一個任務提醒應用程序。但是,我無法讓它通知任務名稱的任務的用戶。這應該是一件相當簡單的事情,但我無法做到。Android應用幫助
我想要做的是:我保存一個名爲「任務3」的任務並在下午6點提醒我。當下午6點到來時,我收到一條通知提示「任務3」。目前,它只是說「任務需要審查」有沒有辦法檢索任務標題並將其作爲通知而不是字符串呈現?
這是提醒服務類類:
公共ReminderService(){ 超( 「ReminderService」); }
@Override
void doReminderWork(Intent intent) {
Log.d("ReminderService", "Doing work.");
Long rowId = intent.getExtras().getLong(RemindersDbAdapter.KEY_ROWID);
NotificationManager mgr = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(this, ReminderEditActivity.class);
notificationIntent.putExtra(RemindersDbAdapter.KEY_ROWID, rowId);
PendingIntent pi = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_ONE_SHOT);
//這是我需要改變的方式。
Notification notification=new Notification(android.R.drawable.stat_sys_warning, getString(R.string.notify_new_task_message), System.currentTimeMillis());
notification.setLatestEventInfo(this, getString(R.string.notify_new_task_title), getString(R.string.notify_new_task_message), pi);
,這是remindersadapter類
* @param reminderDateTime the date and time the reminder should remind the user
* @return rowId or -1 if failed
*/
public long createReminder(String title, String body, String reminderDateTime) {
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_TITLE, title);
initialValues.put(KEY_BODY, body);
initialValues.put(KEY_DATE_TIME, reminderDateTime);
return mDb.insert(DATABASE_TABLE, null, initialValues);
}
/**
* Delete the reminder with the given rowId
*
* @param rowId id of reminder to delete
* @return true if deleted, false otherwise
*/
public boolean deleteReminder(long rowId) {
return mDb.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0;
}
/**
* Return a Cursor over the list of all reminders in the database
*
* @return Cursor over all reminders
*/
public Cursor fetchAllReminders() {
return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE,
KEY_BODY, KEY_DATE_TIME}, null, null, null, null, null);
}
/**
* Return a Cursor positioned at the reminder that matches the given rowId
*
* @param rowId id of reminder to retrieve
* @return Cursor positioned to matching reminder, if found
* @throws SQLException if reminder could not be found/retrieved
*/
public Cursor fetchReminder(long rowId) throws SQLException {
Cursor mCursor =
mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
KEY_TITLE, KEY_BODY, KEY_DATE_TIME}, KEY_ROWID + "=" + rowId, null,
null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
/**
* Update the reminder using the details provided. The reminder to be updated is
* specified using the rowId, and it is altered to use the title, body and reminder date time
* values passed in
*
* @param rowId id of reminder to update
* @param title value to set reminder title to
* @param body value to set reminder body to
* @param reminderDateTime value to set the reminder time.
* @return true if the reminder was successfully updated, false otherwise
*/
public boolean updateReminder(long rowId, String title, String body, String reminderDateTime) {
ContentValues args = new ContentValues();
args.put(KEY_TITLE, title);
args.put(KEY_BODY, body);
args.put(KEY_DATE_TIME, reminderDateTime);
return mDb.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId, null) > 0;
}
}
你好,這是正確的。我嘗試使用行ID,但由於某種原因,不會顯示標題,只是單詞「ID」。 – Superunknown 2011-05-08 19:18:17
在上面的答案中查看我的更新。 – Moystard 2011-05-08 19:52:15
嗨,謝謝。字符串提示是否= cursor.getString(cursor.getColumnIndex(RemindersDbAdapter.KEY_TITLE)); 去fetchreminder方法?因爲「光標」無法解析,因此請將其替換爲「 – Superunknown 2011-05-08 20:31:12