NotificationCompat.Builder - 不兼容的类型

时间:2013-12-19 11:00:59

标签: android notifications

我对NotificationCompat.Builder有疑问。对我来说,下面的代码看起来很好,但Android Studio说它不是。这种行为可能是什么原因?

NotificationCompat noti = new NotificationCompat.Builder(this)
   .setContentTitle("service")
   .setContentText("running")
   .setSmallIcon(R.drawable.ic_launcher)
   .setContentIntent(pendIntent)
   .setPriority(NotificationCompat.PRIORITY_HIGH)
   .addAction(R.drawable.ic_launcher, "Stop", pIntent)
   .build();

IDE错误:

Incompatibile types.
Required: android.support.v4.app.NotificationCompat
Found: android.app.Notification

2 个答案:

答案 0 :(得分:0)

你需要包含android支持库并导入它

import android.support.v4.app.NotificationCompat;

答案 1 :(得分:0)

我想我现在明白了。某种方式通知对象必须是android.app.Notification类型,而不是android.support.v4.app.NotificationCompat

解决方案如下:

 Notification noti = new NotificationCompat.Builder(this)