Android通知“无法解析ABS片段中的方法"build()" [英] Android Notification 'Cannot resolve method 'build()' from ABS Fragment

查看:148
本文介绍了Android通知“无法解析ABS片段中的方法"build()"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在ActionBarSherlock布局中显示来自片段的基本通知.我一直在在此跟随教程以及在Android开发人员页面上,但是我在最后一行收到错误无法解析方法'build()".我已经导入了android.support.v4.app.NotificationCompat.app.NotificationManager

I am attempting to show a basic notification from a fragment in an ActionBarSherlock layout. I have been following the tutorial here as well as the one on the Android Developer pages, but I am getting the error 'Cannot resolve method 'build()' on the last line. I have imported android.support.v4.app.NotificationCompat and .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());,它将起作用.为什么会这样?

If I change the last line to mNotificationManager.notify(1,mBuilder.getNotification()); it works. Why is this?

推荐答案

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

It worked with me for both build() and getNotification() . FYI , Notification.Builder.build() is API level 16 so check your target. Also check your imports and build paths and clean the project. If the problem persists try another android-support-v4.jar inside libs may be its corrupted.

希望这会有所帮助.

这篇关于Android通知“无法解析ABS片段中的方法"build()"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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