【问题标题】:Notification notify() wrong arguments通知 notify() 错误参数
【发布时间】:2013-09-05 09:07:30
【问题描述】:

我使用 NotificationCompat.Builder 构建了一个通知并显示它,我需要通知 NotificationManager 新的通知,所以我正在调用

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

但 Eclipse 将“notif(..)”标记为错误并带有标题:

Object类型中的notify()方法不适用于参数(int, Notification)

我很确定 notif(int, Notification) 存在: http://developer.android.com/reference/android/app/NotificationManager.html

谁能解释我做错了什么?

编辑: 我还发现我无法导入 android.app.NotificationManager,原因是:

导入的 android.app.NotificationManager 与同一文件中定义的类型冲突

【问题讨论】:

  • 清理你的项目。那么它应该可以工作了。
  • @Sajmon 已经尝试过了...没有结果。
  • @Sajmon 最后你的答案是部分正确的 - 查看被选为答案的帖子。

标签: android android-notifications


【解决方案1】:

我正在使用 Notification Compat Builder 和 Notification Manager 来生成通知,它对我来说很好用。粘贴下面的工作代码,检查您是否遗漏了什么:

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());

【讨论】:

  • 那么这意味着,它在构建您的项目时出现问题..尝试清理和构建您的项目。
  • 我已经尝试了几次......但是当我创建新项目并粘贴它时它工作......该死的日食和清洁和建设项目,我将不得不再次导入项目或其他东西。谢谢。
猜你喜欢
  • 2015-10-04
  • 1970-01-01
  • 2019-02-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多