Michał Tajchert
Michał Tajchert

Reputation: 10383

Notification notify() wrong arguments

I building a notifiaction with NotificationCompat.Builder and to show it I need to notify NotificationManager about new notifation, so I'm calling

NotificationManager mNotifyMgr = (NotificationManager) cont.getSystemService(Context.NOTIFICATION_SERVICE);
mNotifyMgr.notify(SOME_INT_NUMBER, builder.build());

but eclipse marks "notif(..)" as error with caption:

The method notify() in the type Object is not applicable for the arguments (int, Notification)

And I'm pretty sure notif(int, Notification) exists: http://developer.android.com/reference/android/app/NotificationManager.html

Can somebody explain what I'm doing wrong?

EDIT: I discovered also I can't import android.app.NotificationManager, due to:

The import android.app.NotificationManager conflicts with a type defined in the same file

Upvotes: 0

Views: 1541

Answers (1)

Nargis
Nargis

Reputation: 4787

I am using the Notification Compat Builder and Notification Manager to generate notifications and it works just fine for me. Pasting the working code below, check if you have missed out something:

import android.app.NotificationManager;
import android.support.v4.app.NotificationCompat;

 final int notificationID = (int)System.currentTimeMillis();
 final int icon = R.drawable.nf_notification;
 final NotificationManager notificationManager = (NotificationManager)context
                .getSystemService(Context.NOTIFICATION_SERVICE);
 final NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setSmallIcon(icon)
                .setContentTitle(title).setStyle(new NotificationCompat.BigTextStyle().bigText(message))
                .setContentIntent(intent).setAutoCancel(true).setContentText(message);
 notificationManager.notify(notificationID, builder.build());

Upvotes: 1

Related Questions