0
我想從eventreminder創建事件提醒警報。但爲什麼警報沒有顯示?我想提醒服務
我在清單中有android.permission.SYSTEM_ALERT_WINDOW。
這是eventreminder服務的代碼:
package com.example.android.eventreminder;
import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.database.Cursor;
import android.util.Log;
import android.view.WindowManager;
/* This class is responsible for notification when an alarm and proximity alert are fired
* Sets up pending intent which is used by notification system.
* Pending intent contains intent to start ViewReminder Activity when notification is clicked*/
public class EventReminderService extends WakeReminderIntentService {
private eventDB mDbHelper;
private String notificationTitle;
public EventReminderService() {
super("EventReminderService");
}
@Override
void doReminderWork(Intent intent) {
/* Status bar notification */
/* when the notification is selected from status bar,
* ViewReminder activity will be started using rowId as part of
* pending intent. ViewReminder activity will be used to display
* event data, to delete event and to snooze time-based event*/
AlertDialog d = new AlertDialog.Builder(this)
.setTitle("tanchulai")
.setMessage("bucuo de tanchulai")
.create();
d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
d.show();
Long rowId = intent.getExtras().getLong(eventDB.KEY_ROWID);
NotificationManager mgr = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
/* Add reminder activity will started when notification is selected */
Intent notificationIntent = new Intent(this, ViewReminder.class);
notificationIntent.putExtra(eventDB.KEY_ROWID, rowId);
int rowID = rowId.intValue();
/* set pending intent */
PendingIntent pi = PendingIntent.getActivity(this, rowID, notificationIntent,
PendingIntent.FLAG_ONE_SHOT);
Log.d("TAG", "PI in ERSer for: "+rowID);
/* set notification for status bar */
Notification note=new Notification(android.R.drawable.stat_sys_warning,
getString(R.string.notify_new_task_message),
System.currentTimeMillis());
mDbHelper = new eventDB(this);
mDbHelper.open();
Cursor notificationData = mDbHelper.fetchEvent(rowId);
/* get title of the event*/
notificationTitle = notificationData.getString(
notificationData.getColumnIndexOrThrow(eventDB.KEY_TITLE));
note.setLatestEventInfo(this, notificationTitle,
getString(R.string.notify_new_task_message), pi);
notificationData.close();
mDbHelper.close();
/* Set default notification sound */
note.defaults |= Notification.DEFAULT_SOUND;
/* Cancel notification after selection by user */
note.flags |= Notification.FLAG_AUTO_CANCEL;
int id = (int)((long)rowId);
/* produce notification on status bar */
mgr.notify(id, note);
}
}
@DanielNugent我不使用通知生成器。所以我必須做什麼? –
它看起來像你使用不推薦的方法,看到這個職位:http://stackoverflow.com/questions/16852270/how-to-implement-the-deprecated-methods-of-notification –