未为Notification.builder定义方法build()

加布里奥

我快要建立通知了。我在网络上阅读到我需要更新我的图书馆的信息。我右键单击该项目;适当,我未选中,在下载了最后一个软件包后,重新检查了我的库android.support.v7。当我重新启动Eclipse时,我也遇到了同样的错误。我认为我不知道如何更新库。请帮我编辑:我将notification.builder更改为notificationcompat.builder()我可以编译项目,但是现在我有此错误日志

package com.example.simplenotification;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RemoteViews;

public class MainActivity extends Activity {

 private static final int MY_NOTIFICATION_ID = 0;

 private int mNotificationCount;

 private final CharSequence tickerText ="this is tickerText";
 private final CharSequence contentTitle="this contentTitle";
 private final CharSequence contentText="this coontentText";

 private Intent mNotificationIntent;
 private PendingIntent mContentIntent;

 RemoteViews mContentView = new RemoteViews("com.example.simplenotification.StatusBarWithCustomView", R.layout.custom_view);
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mNotificationIntent = new Intent(getApplicationContext(),AppGet.class);
    mContentIntent = PendingIntent.getActivity(getApplicationContext(), 0, mNotificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
    final Button button = (Button) findViewById(R.id.button1);


    button.setOnClickListener(new OnClickListener() {


        public void onClick(View v){
            mContentView.setTextViewText(R.id.textView1, contentText + "(" + ++mNotificationCount +")");


            NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(MainActivity.this)
            .setTicker(tickerText)
            .setSmallIcon(android.R.drawable.stat_notify_more)
            .setAutoCancel(true)
            .setContentIntent(mContentIntent)
            .setContent(mContentView);

            NotificationManagerCompat mNotificationManager = NotificationManagerCompat.from(MainActivity.this);
            mNotificationManager.notify(MY_NOTIFICATION_ID,notificationBuilder.build());
        }


        }



    });



 }

}

错误日志显示以下内容:

09-18 11:19:22.344: E/AndroidRuntime(978): FATAL EXCEPTION: main
09-18 11:19:22.344: E/AndroidRuntime(978): android.app.RemoteServiceException: Bad       notification posted from package com.example.simplenotification: Couldn't expand   RemoteViews for: StatusBarNotification(package=com.example.simplenotification id=0 tag=null  notification=Notification(contentView=com.example.simplenotification.StatusBarWithCustomView/0x7f030019 vibrate=null,sound=null,defaults=0x0,flags=0x10) priority=0)
09-18 11:19:22.344: E/AndroidRuntime(978):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1259)
09-18 11:19:22.344: E/AndroidRuntime(978):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-18 11:19:22.344: E/AndroidRuntime(978):  at android.os.Looper.loop(Looper.java:137)
09-18 11:19:22.344: E/AndroidRuntime(978):  at android.app.ActivityThread.main(ActivityThread.java:4340)
09-18 11:19:22.344: E/AndroidRuntime(978):  at java.lang.reflect.Method.invokeNative(Native Method)
09-18 11:19:22.344: E/AndroidRuntime(978):  at java.lang.reflect.Method.invoke(Method.java:511)
09-18 11:19:22.344: E/AndroidRuntime(978):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-18 11:19:22.344: E/AndroidRuntime(978):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-18 11:19:22.344: E/AndroidRuntime(978):  at dalvik.system.NativeStart.main(Native Method)
拉维·巴亚尼(Ravi Bhayani)

更改您的代码,如下所示:

public void onClick(View v){

            NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext())
            .setTicker(tickerText)
            .setSmallIcon(android.R.drawable.stat_notify_more)
            .setAutoCancel(true)
            .setContentIntent(mContentIntent)

            NotificationManagerCompat mNotificationManager = NotificationManagerCompat.from(getApplicationContext());
            mNotificationManager.notify(MY_NOTIFICATION_ID,notificationBuilder.build());
        }

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

the method build() is undefined for Notification.builder

분류에서Dev

메소드 build ()는 Notification.builder에 대해 정의되지 않았습니다.

분류에서Dev

Notification.Builder.setSound has no effect

분류에서Dev

Android: How to adjust the largeIcon of a NotificationCompat.Builder in the bounds of the notification

분류에서Dev

Phonegap Build , using Firebase, notification icon is just white/grey square

분류에서Dev

빌드가 Notification.Builder에 정의되지 않았습니다.

분류에서Dev

java.lang.NoSuchMethodError : android.app.Notification $ Builder.setColor

분류에서Dev

My app unexpectedly asks for notification permission when build with xcode6 for ios8

분류에서Dev

builder.jar 찾을 수 없습니다 (com.android.tools.build:builder:3.1.0)

분류에서Dev

搜索算法,复杂度为O(log n),列表/数组未排序

분류에서Dev

Html.TextBoxFor()在字段集中时未显示在视图中或显示为文本

분류에서Dev

在命令定义后将感叹号处理为:wq

분류에서Dev

Python notification

분류에서Dev

Push notification for azure notification hub

분류에서Dev

状态列表可绘制的自定义单选按钮未更改

분류에서Dev

为自定义域配置Google App Engine SSL

분류에서Dev

将PI定义为小数点后第36位

분류에서Dev

在Agda中将构造函数编写为函数的更好方法

분류에서Dev

按类型调用通用方法,其中类型为接口

분류에서Dev

Message overflow in notification bubble

분류에서Dev

Laravel Echo not listening notification

분류에서Dev

Push Notification Android

분류에서Dev

Jquery notification (onload)

분류에서Dev

How to disable thunderbird notification

분류에서Dev

push notification using Django

분류에서Dev

The intent in notification does not work

분류에서Dev

IOS Reachability notification in Background

분류에서Dev

Android Reminder Notification

분류에서Dev

Android wear not show notification

Related 관련 기사

  1. 1

    the method build() is undefined for Notification.builder

  2. 2

    메소드 build ()는 Notification.builder에 대해 정의되지 않았습니다.

  3. 3

    Notification.Builder.setSound has no effect

  4. 4

    Android: How to adjust the largeIcon of a NotificationCompat.Builder in the bounds of the notification

  5. 5

    Phonegap Build , using Firebase, notification icon is just white/grey square

  6. 6

    빌드가 Notification.Builder에 정의되지 않았습니다.

  7. 7

    java.lang.NoSuchMethodError : android.app.Notification $ Builder.setColor

  8. 8

    My app unexpectedly asks for notification permission when build with xcode6 for ios8

  9. 9

    builder.jar 찾을 수 없습니다 (com.android.tools.build:builder:3.1.0)

  10. 10

    搜索算法,复杂度为O(log n),列表/数组未排序

  11. 11

    Html.TextBoxFor()在字段集中时未显示在视图中或显示为文本

  12. 12

    在命令定义后将感叹号处理为:wq

  13. 13

    Python notification

  14. 14

    Push notification for azure notification hub

  15. 15

    状态列表可绘制的自定义单选按钮未更改

  16. 16

    为自定义域配置Google App Engine SSL

  17. 17

    将PI定义为小数点后第36位

  18. 18

    在Agda中将构造函数编写为函数的更好方法

  19. 19

    按类型调用通用方法,其中类型为接口

  20. 20

    Message overflow in notification bubble

  21. 21

    Laravel Echo not listening notification

  22. 22

    Push Notification Android

  23. 23

    Jquery notification (onload)

  24. 24

    How to disable thunderbird notification

  25. 25

    push notification using Django

  26. 26

    The intent in notification does not work

  27. 27

    IOS Reachability notification in Background

  28. 28

    Android Reminder Notification

  29. 29

    Android wear not show notification

뜨겁다태그

보관