Programming

수정 방법 : android.app.RemoteServiceException : 패키지에서 게시 된 잘못된 알림 * : 아이콘을 작성할 수 없음 : StatusBarIcon

procodes 2020. 8. 3. 21:50
반응형

수정 방법 : android.app.RemoteServiceException : 패키지에서 게시 된 잘못된 알림 * : 아이콘을 작성할 수 없음 : StatusBarIcon


충돌 로그에 다음 예외가 나타납니다.

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 파일"입니다.

In my xml file I was added one View in between the LinearLayout for divider.

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

The above View component creating the Bad notification exception. This Exception reason is only xml file of Remoteviews.

After removing that View component, My code executed properly, without any exception. So I felt that Notification drawer not accepting any customized views.

So you don't draw any thing like the above view in the .xml file of RemoteView object.


In my app, this kind of bug happens only during upgrading. If the resource id changes in the newer version, Android RemoteView may fail to find the resource and throw out the RemoteServiceException. If you publish a 3rd version and do not change the resource id, the bugs may disappear only temporarily.

It is possible to reduce this kind of bugs by editing res/values/public.xml and res/values/ids.xml. Compiler will generate an individual resource id if the resource id is not in public.xml or ids.xml. When u change the resource name or add some new resources, the id may change and some devices may fail to find it.

So the step is as following:

  1. Decompile the apk file and in res/values find the public.xml and ids.xml
  2. Find all resources related to RemoteView in your app and copy them ( strings, dimen, drawable, layout, id, color... )
  3. Create public.xml and ids.xml under res/values in your source code and paste the lines u just copied

Note:

Gradle 1.3.0 and above ignore the local public.xml. To make it work, u need to add some script in your 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)
            }
        }
    }
}

Note: This script does not support submodules project. I am trying to fix it.


My problem was that the icon I was using on

.setSmallIcon(R.drawable.ic_stat_push_notif)

wasn't generated accordingly. According to the official doc:

As described in Providing Density-Specific Icon Sets and Supporting Multiple Screens, you should create separate icons for all generalized screen densities, including low-, medium-, high-, and extra-high-density screens. This ensures that your icons will display properly across the range of devices on which your application can be installed.

So the best way to fullfill the above, I used Notification Generator provided by Roman Nurik on https://romannurik.github.io/AndroidAssetStudio/index.html

In that way, you can use an image (taking into consideration that this has to have transparent background) and let the generator do the job for you generating the different sizes for notification icons.

The most important thing is that if the icon generator after you browse the image you are going to use shows you a white filled circle or square, there are problems with your image, maybe because it doesn't have any transparencies, so make sure that you has this ok.


You have pass same icon

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

and you notification

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

I had RemoteServiceException when use Notification in my class extends from FirebaseMessagingService. I added the following code to AndroidManifest.xml:

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

Also resource ic_small set in instance of a class Notification.Builder by method setSmallIcon(int icon).


In Android Studio version 3.0.0 and above, when adding a new image in the drawables folder choose drawable instead of drawable-v24.enter image description here

If the image,you are using, is alread a (v24) just copy it and paste it in its same directory (eg. drawables). This time it will ask you which regular or v24 - just make sure its not the v24 and try it again this should fix the error.


Same issue happened with me as well and I have solved the same

REASON: This is happening because of we are using vector drawable for RemoteViews and vector drawable generates drawable at compile-time. Also I am not sure why some devices are not able to detect the generated drawable resources id while we are upping the app. But yes this was the reason.

REPRODUCE Steps 1. Install previous build. 2. Send a notification 3. Update the build with next version code 4. After updating the app don't open the app and send notification again

SOLUTION Replace the vector drawable with normal drawable(.png or .jpg) file.

I hope this resolves the problem.


I had the same issue when I set a notification in a bundle. I tried this and it solved my problem:

builder.setLargeIcon(large_icon);
builder.setSmallIcon(R.drawable.small_icon);

Make sure that setLargeIcon() invoked before setSmallIcon().


I too had the same issue. The issue is with the icon which you are using, I was using android.R.drawable.stat_sys_download. Go to drawables.xml and paste this.

<resources>
 <item name="ic_start_download" type="drawable">@android:drawable/stat_sys_download</item>
</resource>

and then in your code

builder.setSmallIcon(R.drawable.ic_start_download);

You can try some other image instead of this image


My way to solve this: I had "bad" views in my layout (ex: a checkbox) - so I removed them.

RemoteViews seem to support only images and texts (to be confirmed by reading the doc).


I had RemoteServiceException when use android.support.constraint.ConstraintLayout. Change it to LinearLayout or Relative and also android:layout_height="wrap_content" for container


(this is not solution for current question but helps someone with similar core issue) I too had the same issue, But in my case I have used corrupted .png file which is causing same issue. So I have deleted it and re-included correct .png file.


Please replace <android.support.v7.widget.AppCompatTextView with <TextView from custom notification layout.

Because android.support.v7.widget.AppCompatTextView or android.support.v7.widget.AppCompatImageView only works at runtime.

So Use TextView or ImageView


If any one still facing this issue : Add a png file in your drawable folder with name ic_stat_ic_notification (or any name u like )

and in your manifest add below couple of lines

and u can create your icons over here - > https://romannurik.github.io/AndroidAssetStudio/icon


Just in case the icon is not important, you can replace,

R.drawable.your_icon

To

android.R.drawable.some_standard_icon

This works!


Synchrinize the project and than Clean it, File > Synchronize then : Build > Clean Project

I hope that will help you all, It's work for me


This worked for me. Comment the reference of the icon and thus be able to use the NotificationCompat.Builder without problems.

    $msg_notificacion = [
                        'title'         => "titulonotif",
                       // "icon" : "myicon",
                        'body'          =>"cuerponotif"
                    ];

참고URL : https://stackoverflow.com/questions/25317659/how-to-fix-android-app-remoteserviceexception-bad-notification-posted-from-pac

반응형