Nofication.Builder不起作用

时间:2016-10-07 10:48:26

标签: android android-studio

enter image description here

当我将鼠标悬停在物体上时,按摩显示:

  

需要android.app.nofication找到android.app.notification.Builder

2 个答案:

答案 0 :(得分:2)

应该是

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(MainActivity.this);

通常,整个代码都是这样的:

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context);

notificationBuilder.setContentTitle("Title");
notificationBuilder.setContentText("Text");
notificationBuilder.setSmallIcon(R.mipmap.your_icon);
notificationBuilder.setTicker("Ticker");
notificationBuilder.setContentIntent(pendingIntent);
notificationBuilder.setAutoCancel(true);

NotificationManager nm = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

nm.notify(notificationID, notificationBuilder.build());

答案 1 :(得分:-1)

您忘记了.build();

像这样:

Notification noti=new Notification.Builder(MainActivity.this).build();