Sarah Bantan
Sarah Bantan

Reputation: 29

Notification manager

I want to create a notification for my app

it tells me that constructor Notification(,,) is deprecated

and also the method .setLatestEventInfo() also deprecated

wt should I do?

This is the class code:

public class ReminderService extends WakeReminderIntentService {

public ReminderService() {
    super ("ReminderService");
}

@Override
void doReminderWork(Intent intent) {
    long rowid = intent.getExtras().getLong(ReminderProvider.COLUMN_ROWID);

    NotificationManager mgr = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
    Intent notificationIntent = new Intent (this, ReminderEditActivity.class);
    notificationIntent.putExtra(ReminderProvider.COLUMN_ROWID, rowid);
    PendingIntent Pi = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_ONE_SHOT);
    Notification note=new Notification(android.R.drawable.stat_sys_warning, getString(R.string.notify_new_task_message), System.currentTimeMillis());
    note.setLatestEventInfo(this, getString(R.string.notify_new_task_title), getString(R.string.notify_new_task_message), Pi);
    note.defaults |= Notification.DEFAULT_SOUND;
    note.flags |= Notification.FLAG_AUTO_CANCEL;
    int id = (int) ((long) rowid);
    mgr.notify(id, note);

}

}

Upvotes: 0

Views: 353

Answers (2)

YealBen
YealBen

Reputation: 11

NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!")
.setContentIntent(pendingIntent);

try something like that

Upvotes: 1

XorOrNor
XorOrNor

Reputation: 8978

Use NotificationCompat.Builder for this. http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html

Upvotes: 1

Related Questions