Android应用程序帮助 [英] Android Application Help
问题描述
您好我已经创建了一个任务提醒应用程序。但我无法得到它的通知与任务名称任务的用户。这应该是一个相当简单的事情,但我无法做到这一点。
Hi I have created a task reminder application. However I am unable to get it to notify the user of the task with the task name. It should be a fairly simple thing to do, but I am unable to do it.
我希望它做的是:我救了一个名为任务3,并提醒我下午6点的任务。下午6点时谈到,我得到通知警告说:任务3。目前,它只是说任务需要进行审查有没有检索任务标题和presenting它作为一个通知,而不是一个字符串的方法是什么?
What I want it to do is: I save a task called "Task 3" and to remind me for 6pm. When 6pm comes, I get a notification alert saying "Task 3". At the moment, it only says "task needs to be reviewed" Is there a way of retrieving the task title and presenting it as a notification instead of a string?
这是提醒服务类类:
公共ReminderService(){
超级(ReminderService);
}
public ReminderService() { super("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);
//这是我需要的方式来改变一下。
//This is the bit I need to change by the way.
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类
and this is the remindersadapter class
* @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;
}
}
推荐答案
如果我理解正确,问题是,您显示string.xml定义的常量字符串。您应该使用行ID你从意图向您数据库中获取相应的提醒,并显示其标题。
If I understand correctly, the problem is that you display a constant string defined in your string.xml. You should use the row id you get from the Intent to fetch the corresponding reminder from you database and display its title.
当你获得从fetchReminder方法光标同时提供行ID,您可以使用让您的提醒标题:
Once you retrieve the cursor from your fetchReminder method while providing the row id, you can get the title of your reminder using:
String reminderTitle = cursor.getString(cursor.getColumnIndex(RemindersDbAdapter.KEY_TITLE));
确认您的光标不是null事先。
Verify that your cursor is not null beforehand.
这篇关于Android应用程序帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!