来自 ABS fragment 的 Android 通知 'Cannot resolve method ' build()'

标签 android android-fragments actionbarsherlock android-notifications

我试图在 ActionBarSherlock 布局中显示来自 fragment 的基本通知。我一直following the tutorial here以及 Android 开发人员页面上的那个,但我在最后一行收到错误“无法解析方法‘build()’”。我已经导入了 android.support.v4.app.NotificationCompat.app.NotificationManager

public void createNotification(){

    NotificationManager mNotificationManager = (NotificationManager)getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getActivity());
    mBuilder.setSmallIcon(R.drawable.icon);
    mBuilder.setContentTitle("Title");
    mBuilder.setContentText("Text");
    mBuilder.setTicker("Ticker");
    mNotificationManager.notify(1,mBuilder.build());
}

如果我将最后一行更改为 mNotificationManager.notify(1,mBuilder.getNotification()); 它会起作用。这是为什么?

最佳答案

它对 build() 和 getNotification() 都适用。 仅供引用,Notification.Builder.build() 是 API 级别 16,因此请检查您的目标。 还要检查您的导入和构建路径并清理项目。如果问题仍然存在,请尝试在库中使用另一个 android-support-v4.jar,它可能已损坏。

希望这对您有所帮助。

关于来自 ABS fragment 的 Android 通知 'Cannot resolve method ' build()',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21294231/

相关文章:

php - 使用 PHP、PDO、MYSQL 将 Android 推送通知发送到多个设备

java - 我想用 Java 为 Android 解析 JSON,但 Gson 和 Jackson 都无法正常工作

android - 没有迹象表明 NPE 可能发生在哪里

android - 带有 Viewpager2 的关键 FragmentStateAdapter 的 fragment 不再存在

android - 不支持的操作异常 : Can't convert to dimension: type=0x1

android - 圈选并选择文本

Android:以编程方式设置样式时不显示 EditText

android - Android 上的 YouTubePlayerFragment 不显示广告 - YouTube Android Player API

android - 检查 splitBarWhenNarrow 是否为真 - 以编程方式 - ActionBarSherlock

android - 为什么没有相机结果?