android - 尝试加载通知时,应用崩溃

标签 android notifications crash remoteview

06-02 06:43:35.978 4227-4227/? I/art: Late-enabling -Xcheck:jni
06-02 06:43:36.088 4227-4227/meet.projectoklahoma W/System: ClassLoader referenced unknown path: /data/app/meet.projectoklahoma-1/lib/x86
06-02 06:43:36.183 4227-4227/meet.projectoklahoma I/GMPM: App measurement is starting up, version: 8487
06-02 06:43:36.183 4227-4227/meet.projectoklahoma I/GMPM: To enable debug logging run: adb shell setprop log.tag.GMPM VERBOSE
06-02 06:43:36.473 4227-4254/meet.projectoklahoma D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
06-02 06:43:36.516 4227-4254/meet.projectoklahoma D/libEGL: loaded /system/lib/egl/libEGL_emulation.so
06-02 06:43:36.517 4227-4254/meet.projectoklahoma D/libEGL: loaded /system/lib/egl/libGLESv1_CM_emulation.so
06-02 06:43:36.532 4227-4254/meet.projectoklahoma D/libEGL: loaded /system/lib/egl/libGLESv2_emulation.so
06-02 06:43:36.575 4227-4254/meet.projectoklahoma I/OpenGLRenderer: Initialized EGL, version 1.4
06-02 06:43:36.658 4227-4254/meet.projectoklahoma W/EGL_emulation: eglSurfaceAttrib not implemented
06-02 06:43:36.658 4227-4254/meet.projectoklahoma W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xed6fcd40, error=EGL_SUCCESS
06-02 06:44:56.177 4227-4254/meet.projectoklahoma W/EGL_emulation: eglSurfaceAttrib not implemented
06-02 06:44:56.177 4227-4254/meet.projectoklahoma W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xed6ff6c0, error=EGL_SUCCESS
06-02 06:44:56.585 4227-4227/meet.projectoklahoma I/Choreographer: Skipped 30 frames!  The application may be doing too much work on its main thread.
06-02 06:44:57.062 4227-4254/meet.projectoklahoma E/Surface: getSlotFromBufferLocked: unknown buffer: 0xf3dd7240
06-02 06:44:59.933 4227-4227/meet.projectoklahoma D/AndroidRuntime: Shutting down VM
06-02 06:44:59.934 4227-4227/meet.projectoklahoma E/AndroidRuntime: FATAL EXCEPTION: main
                                                                    Process: meet.projectoklahoma, PID: 4227
                                                                    android.app.RemoteServiceException: Bad notification posted from package meet.projectoklahoma: Couldn't expand RemoteViews for: StatusBarNotification(pkg=meet.projectoklahoma user=UserHandle{0} id=1 tag=null score=0 key=0|meet.projectoklahoma|1|null|10060: Notification(pri=0 contentView=meet.projectoklahoma/0x7f04001c vibrate=null sound=null defaults=0x0 flags=0x0 color=0x00000000 vis=PRIVATE))
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1507)
                                                                        at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                        at android.os.Looper.loop(Looper.java:148)
                                                                        at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

用户登录后,该应用程序应为他加载等待事件的通知,但它会粉碎。上面的代码是崩溃后我得到的错误。

这是发送通知的代码:
private void sendNotification() {
    if (!LocalDataBase.getCurrentUser().getWaitingList().isEmpty())
    {
        int notificationID=1;
        setContentView(R.layout.activity_events_status_bar2);
        TextView eventName=(TextView)findViewById(R.id.incomingEventsNameText2) ;
        Event eventToDisplay=LocalDataBase.getCurrentUser().getWaitingList().get(0);
        eventName.setTag(eventToDisplay);
        Intent showEvents=new Intent(this, EventsStatusBarActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, showEvents, 0);
        RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.activity_events_status_bar2);
        contentView.setTextViewText(R.id.incomingEventsNameText2, eventToDisplay.getName());
        contentView.setOnClickPendingIntent(R.id.attendButton,pendingIntent);
        contentView.setOnClickPendingIntent(R.id.declineButton,pendingIntent);
        NotificationCompat.Builder eventsNotification= new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.notification_template_icon_bg)
                .setContentText("Incoming notifications")
                .setContent(contentView);
        eventsNotification.setContentIntent(pendingIntent);
        NotificationManager notificationManager=(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(notificationID,eventsNotification.build());
    }


}

这是activity_events_status_bar2的代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:weightSum="1">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Event Name"
        android:tag="event"
        android:id="@+id/incomingEventsNameText2"
        android:layout_gravity="left"
        android:textColor="@android:color/black"
        android:textSize="22sp"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignBottom="@+id/attendButton" />

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Going"
        android:id="@+id/attendButton"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@+id/declineButton"
        android:layout_toStartOf="@+id/declineButton"
        android:onClick="selectGoing"/>

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Not Going"
        android:id="@+id/declineButton"
        android:layout_alignBottom="@+id/attendButton"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:onClick="selectNotGoing"/>


</RelativeLayout>

最佳答案

您可能需要通过直接应用contentView来解决此问题:

     NotificationCompat.Builder eventsNotification= new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.notification_template_icon_bg)
                    .setContentText("Incoming notifications")
                    .setContent(contentView);
            eventsNotification.setContentIntent(pendingIntent);
 NotificationManager notificationManager=(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

     Notification myNotification = eventsNotification.build();
     notification.contentView = contentView;
     notificationManager.notify(notificationID,myNotification);

关于android - 尝试加载通知时,应用崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37587689/

相关文章:

Android 可扩展 ListView 随机播放子项

android - 如何在android中动态更新或更改imageview的图像?

android - 如何将暂停和取消按钮添加到自定义下载通知android

javascript - 如何确定哪种JavaScript导致浏览器崩溃?

android - 如果获取了唤醒锁并且我的应用程序崩溃了,我该怎么办?

java - 在应用程序文件中使用 .getWindow()

android - 防止 Android 中的 Fragment 恢复

android - 如何在通知中向服务发送 PendingIntent 后隐藏通知面板

java - 将数据从通知发送到已关闭的 Activity

objective-c - UIButton:单击时崩溃