Android Notification 'Cannot resolve method 'build()' from ABS Fragment

人盡茶涼 提交于 2019-12-13 01:28:52

问题


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

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


回答1:


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.

Hope this helps.



来源:https://stackoverflow.com/questions/21294231/android-notification-cannot-resolve-method-build-from-abs-fragment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!