수정 방법 : android.app.RemoteServiceException : 패키지에서 게시 된 잘못된 알림 * : 아이콘을 만들 수 없음 : StatusBarIcon 표시됩니다. android.app.RemoteServiceException: Bad notification posted from

충돌 로그에 다음 예외가 표시됩니다.

android.app.RemoteServiceException: Bad notification posted from package com.my.package: Couldn't create icon: StatusBarIcon(pkg=com.my.package user=0 id=0x7f02015d level=0 visible=true num=0 )
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1456)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:146)
    at android.app.ActivityThread.main(ActivityThread.java:5487)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
    at dalvik.system.NativeStart.main(Native Method)

다음 방법을 사용하여 AlarmManager를 통해 설정된 PendingIntent의 IntentService에서 내 알림을 게시하고 있습니다. 여기에 전달 된 모든 값은 PendingIntent / IntentService의 번들 엑스트라에서 가져온 것입니다.

/**
 * Notification 
 *
 * @param c
 * @param intent
 * @param notificationId
 * @param title
 * @param message
 * @param largeIcon
 * @param smallIcon
 */
public static void showNotification(Context c, Intent intent,
        int notificationId, String title, String message, int largeIcon,
        int smallIcon) {
    PendingIntent detailsIntent = PendingIntent.getActivity(c,
            notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    // BUILD
    NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder(
            c);
    // TITLE
    mNotifyBuilder.setContentTitle(title).setContentText(message);

    // ICONS
    mNotifyBuilder.setSmallIcon(smallIcon);
    if (Util.isAndroidOSAtLeast(Build.VERSION_CODES.HONEYCOMB)) {
        Bitmap large_icon_bmp = ((BitmapDrawable) c.getResources()
                .getDrawable(largeIcon)).getBitmap();
        mNotifyBuilder.setLargeIcon(large_icon_bmp);
    }

    mNotifyBuilder.setContentIntent(detailsIntent);
    mNotifyBuilder.setVibrate(new long[] { 500, 1500 });
    mNotifyBuilder.setTicker(message);
    mNotifyBuilder.setContentText(message);

    // NOTIFY
    NotificationManager nm = (NotificationManager) c
            .getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(notificationId, mNotifyBuilder.build());
}

내가 다른 답변에서 본 것에서-내가보고있는 예외 setSmallIcon()는 제대로 호출되지 않을 때 발생합니다 .

전달되는 리소스 ID가 모두 올바른지 확인하고 두 번 확인했습니다.



답변

무슨 일이 있었는지 PendingIntent 번들의 아이콘에 대한 정수 참조를 포함하고 있었고 그 정수는 나중에 NotificationManager에 게시되는 동안 참조되었습니다.

정수 참조를 가져오고 보류중인 인 텐트가 시작되는 사이에 앱이 업데이트되고 모든 드로어 블 참조가 변경되었습니다. 올바른 드로어 블을 참조하는 데 사용 된 정수가 이제 잘못된 드로어 블을 참조하거나 전혀 참조하지 않았습니다 (전혀 없음-이 충돌을 일으킴).


답변

VectorXml알림 내부를 사용 하면이 문제가 발생하는 것으로 알려져 있습니다. PNG 사용


답변

Kitkat에서 SVG를 사용하지 마십시오!

Kitkat에 알림을 표시하고 싶을 때마다 같은 문제가 발생했습니다. 나에게 문제를 일으킨 것은 xml의 모든 아이콘 (svg에서), 작은 아이콘 및 작업 아이콘도 정의했기 때문입니다. 내가 그들을 png-s로 교체 한 후 문제는 내 편에서 해결되었습니다.


답변

android.app.RemoteServiceException : 잘못된 알림이 게시 됨

나는 같은 문제가 있었지만 해결되었습니다. 내 문제는 원격보기의 “.xml 파일”입니다.

내 xml 파일 에서 구분선 View사이 에 하나 를 추가 했습니다 LinearLayout.

<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:id="@+id/view"
    android:background="#000000" />

View잘못된 알림 예외를 생성하는 위의 구성 요소입니다. 이 예외 이유는 Remoteviews의 xml 파일입니다.

해당 View 구성 요소를 제거한 후 내 코드가 예외없이 제대로 실행되었습니다. 그래서 알림 서랍이 사용자 정의 된 뷰를 받아들이지 않는다고 느꼈습니다.

따라서 RemoteView객체 의 .xml 파일에 위의보기와 같은 것을 그리지 않습니다 .


답변

내 문제는 내가 사용하고 있던 아이콘이

.setSmallIcon(R.drawable.ic_stat_push_notif)

그에 따라 생성되지 않았습니다. 공식 문서 에 따르면 :

밀도 별 아이콘 세트 제공 및 다중 화면 지원에 설명 된대로 저밀도, 중 밀도, 고밀도 및 초 고밀도 화면을 포함하여 모든 일반화 된 화면 밀도에 대해 별도의 아이콘을 만들어야합니다. 이렇게하면 응용 프로그램을 설치할 수있는 장치 범위에서 아이콘이 제대로 표시됩니다.

따라서 위 내용을 채우는 가장 좋은 방법 은 https://romannurik.github.io/AndroidAssetStudio/index.html에서 Roman Nurik이 제공 하는 알림 생성기를 사용했습니다.

그런 식으로 이미지를 사용하고 (투명한 배경이 있어야한다는 점을 고려) 생성기가 알림 아이콘에 대해 다양한 크기를 생성하도록 할 수 있습니다.

가장 중요한 것은 사용할 이미지를 탐색 한 후 아이콘 생성기가 흰색으로 채워진 원이나 사각형을 표시하는 경우 이미지에 문제가있는 것입니다. 투명도가 없기 때문일 수 있으므로 괜찮아요.


답변

내 앱에서 이런 종류의 버그는 업그레이드 중에 만 발생합니다. 최신 버전에서 리소스 ID가 변경되면 Android RemoteView가 리소스를 찾지 못하고 RemoteServiceException. 세 번째 버전을 게시하고 리소스 ID를 변경하지 않으면 버그가 일시적으로 만 사라질 수 있습니다 .

res/values/public.xml및 .NET을 편집 하여 이러한 종류의 버그를 줄일 수 있습니다 res/values/ids.xml. 리소스 ID가 public.xml또는에 없는 경우 컴파일러는 개별 리소스 ID를 생성합니다 ids.xml. 리소스 이름을 변경하거나 새 리소스를 추가하면 ID가 변경되어 일부 장치에서 찾지 못할 수 있습니다.

따라서 단계는 다음과 같습니다.

  1. APK에 파일을 디 컴파일에 res/values찾아 public.xmlids.xml
  2. 앱에서 RemoteView와 관련된 모든 리소스를 찾아 복사합니다 (문자열, 치수, 드로어 블, 레이아웃, ID, 색상 …).
  3. 작성 public.xmlids.xml아래에 res/values소스 코드와 u는 방금 복사 한 라인을 붙여

노트 :

Gradle 1.3.0 이상에서는 로컬 public.xml. 작동하게하려면 다음과 같은 스크립트를 추가해야합니다.build.gradle

afterEvaluate {
    for (variant in android.applicationVariants) {
        def scope = variant.getVariantData().getScope()
        String mergeTaskName = scope.getMergeResourcesTask().name
        def mergeTask = tasks.getByName(mergeTaskName)
        mergeTask.doLast {
            copy {
                int i=0
                from(android.sourceSets.main.res.srcDirs) {
                    include 'values/public.xml'
                    rename 'public.xml', (i == 0? "public.xml": "public_${i}.xml")
                    i++
                }
                into(mergeTask.outputDir)
            }
        }
    }
}

참고 :이 스크립트는 하위 모듈 프로젝트를 지원하지 않습니다. 나는 그것을 고치려고 노력하고있다.


답변

동일한 아이콘을 통과했습니다.

     <meta-data
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@drawable/ic_stat_name" />

그리고 당신은 알림

 NotificationCompat.Builder notificationBuilder =
                new NotificationCompat.Builder(this, channelId)
                        .setSmallIcon(R.drawable.ic_stat_name)
                        .setContentTitle("Title")
                        .setContentText(messageBody)
                        .setAutoCancel(true)
                        .setSound(defaultSoundUri)
                        .setContentIntent(pendingIntent);