2

RemoteViews 위젯으로 사용자 정의 알림을 구현했습니다. Android 5.0.2 및 Android 6.0에서 테스트했습니다. 그것은 잘 작동했다. 그러나 언젠가 후에, 그것은 GCM으로부터 통보를받을 때마다 부서지기 시작했습니다.android.app.RemoteServiceException : 패키지에서 올린 잘못된 알림입니다. RemoteViews를 확장 할 수 없습니다. StatusBarNotification

크래시 덤프 - 리모트 뷰 RemoteViews에 대한

Process: package.name, PID: 27743 
android.app.RemoteServiceException: Bad notification posted from package package.name: Couldn't expand RemoteViews for: StatusBarNotification(pkg=package.name user=UserHandle{0} id=1524095391 tag=null key=0|package.name|1524095391|null|10247: Notification(pri=0 contentView=package.name/0x7f040033 vibrate=null sound=null defaults=0x0 flags=0x10 color=0x00000000 category=recommendation vis=PUBLIC)) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6077) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 

내 레이아웃이있는 LinearLayout 및 텍스트 뷰를 확장하고 사용자 정의 텍스트 뷰 클래스 내에서 이미지 뷰가 있습니다. 통지를 만들기위한

내 코드

private void showCustomNotification(ABCNotification notification) { 
     RemoteViews notificationView = new RemoteViews(getPackageName(), R.layout.layout_notification); 
     PendingIntent contentPendingIntent = PendingIntent.getBroadcast(mContext, 0, notification.getContentIntent(), PendingIntent.FLAG_UPDATE_CURRENT); 

       NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext); 
       builder.setSmallIcon(R.drawable.ic_notification).setAutoCancel(true).setContentIntent(contentPendingIntent); 

       // Set Notification Priority 
       builder.setPriority(notification.getNotificationPriority()); 

       // Set Notification Category 
       builder.setCategory(notification.getNotificationCategory()); 

       // Set Notification Visibility 
       builder.setVisibility(notification.getNotificationVisibility()); 

notificationView.setTextViewText(R.id.tv_notification_title, notification.getTitle()); 
     notificationView.setTextViewText(R.id.tv_notification_message, notification.getMessage()); 
     notificationView.setTextViewText(R.id.tv_notification_subtext, notification.getSubtext()); 
     Notification notif = builder.build(); 
       if (null != notif) { 
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { 
         notif.bigContentView = notificationView; 
        } 
        notif.contentView = notificationView; 
        NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); 
        notificationManager.notify(mNotificationId, notif); 
       } 
    } 

리모트 뷰 RemoteViews에 대한 나의 레이아웃 내가 스택 오버 플로우에 대한 거의 모든 솔루션을 보았다이

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:paddingBottom="4dp" 
      android:paddingTop="4dp"> 

      <com.abc.ui.customviews.fonts.TextViewYMRegular 
       android:id="@+id/tv_notification_title" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="8dp" 
       android:ellipsize="end" 
       android:singleLine="true" 
       android:textColor="@color/black" 
       android:textSize="16sp" /> 

      <com.abc.ui.customviews.fonts.TextViewYMMedium 
       android:id="@+id/tv_notification_message" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="8dp" 
       android:textColor="@color/black" 
       android:textSize="14sp" /> 

      <com.abc.ui.customviews.fonts.TextViewYMMedium 
       android:id="@+id/tv_notification_subtext" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:textColor="@color/black" 
       android:textSize="12sp" /> 
     </LinearLayout> 

</LinearLayout> 

같은입니다. 아무것도 작동하는 것 같습니다.

재미있는 부분은 완벽하게 작동하고 있다는 것입니다. 그러나 언젠가 충돌하기 시작했습니다. 2 시간 내에 있습니다.

+1

'RemoteViews'에 대해 사용자 정의 '보기'를 사용할 수 없습니다. [여기에 나열된] 클래스 (https://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout) 만 사용할 수 있습니다. "이러한 클래스의 자손은 지원되지 않습니다." –

+1

감사합니다. 사용자 지정 TextViews 문제가 보인다. 이제는 고정. :-) –

답변

4

Mike에 의해 논평 되었 듯이, 네이티브 뷰의 직접 자손 인 경우에도 사용자 지정 뷰를 사용할 수 없습니다.

TextView를 확장하고 있던 TextViewYMRegular를 사용하고있었습니다. 모든 사용자 지정 TextViews를 기본 텍스트로 변경했습니다.

listed here은 RemoteViews에서만 사용할 수 있습니다.