NotificationCompat.Builder - Incompatibile类型 [英] NotificationCompat.Builder - Incompatibile types

查看:202
本文介绍了NotificationCompat.Builder - Incompatibile类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 NotificationCompat.Builder 的一个问题。对我来说,下面的code看起来不错,但Android的工作室表示,事实并非如此。有什么能这种行为的原因是什么?

  NotificationCompat的NotI =新NotificationCompat.Builder(本)
   .setContentTitle(服务)
   .setContentText(运行)
   .setSmallIcon(R.drawable.ic_launcher)
   .setContentIntent(pendIntent)
   .setPriority(NotificationCompat.PRIORITY_HIGH)
   .addAction(R.drawable.ic_launcher,停止,pIntent)
   。建立();

IDE错误:

  Incompatibile类型。
要求:android.support.v4.app.NotificationCompat
实测:android.app.Notification


解决方案

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

该解决方案如下:

 通知NotI位=新NotificationCompat.Builder(本)

I have a problem with NotificationCompat.Builder. For me the code below looks fine but the Android Studio says it is not. What could be the reason of such behavior?

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 error:

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

解决方案

I think now I get it. Somehow notification object must be of android.app.Notification type, not the android.support.v4.app.NotificationCompat.

the solution is following:

 Notification noti = new NotificationCompat.Builder(this)

这篇关于NotificationCompat.Builder - Incompatibile类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆