Android TransactionTooLargeException with NotificationManager

旧时模样 提交于 2019-12-24 22:16:40

问题


I am getting TransactionTooLargeException exception when sending a notification with a custom layout.

java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 588636 bytes
       at android.app.NotificationManager.notifyAsUser(NotificationManager.java:380)
       at android.app.NotificationManager.notify(NotificationManager.java:286)
       at android.app.NotificationManager.notify(NotificationManager.java:270)

It's probably because of the bitmaps in the layout, but it's not happening on all of the devices, so I don't want to reduce or remove those bitmaps, is there anything else I can do?

This is my layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="64dp"
    android:background="@color/colorPrimary"
    android:orientation="horizontal">


    <ImageView
        android:layout_margin="0dp"
        android:id="@+id/userImage"
        android:layout_width="64dp"
        android:layout_height="64dp"
        tools:src="@tools:sample/avatars" />

    <LinearLayout
        android:layout_marginStart="5dp"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <TextView
            android:maxLines="1"
            android:id="@+id/userName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/yellow"
            android:textSize="20sp"
            android:textStyle="bold"
            tools:text="@tools:sample/full_names" />

        <TextView
            android:id="@+id/time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:textColor="@color/yellow"
            android:textStyle="bold"
            tools:text="0:25" />

    </LinearLayout>


    <ImageView
        android:id="@+id/muteButton"
        android:padding="1dp"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_gravity="center"
        android:layout_marginStart="8dp"
        android:background="@drawable/circle2"
        android:src="@drawable/mute_icon"
        android:tint="@color/black" />

    <ImageView
        android:id="@+id/micButton"
        android:padding="1dp"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_gravity="center"
        android:layout_marginStart="8dp"
        android:background="@drawable/circle2"
        android:src="@drawable/speaker"
        android:tint="@color/black" />

    <ImageView
        android:id="@+id/endCallButton"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:layout_marginStart="8dp"
        android:background="@drawable/circle2"
        android:src="@mipmap/call_end_icon" />

    <ImageView
        android:visibility="gone"
        android:id="@+id/answerButton"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:layout_marginStart="8dp"
        android:background="@drawable/circle2"
        android:src="@mipmap/call_icon" />

    <FrameLayout
        android:layout_width="8dp"
        android:layout_height="0dp"/>

</LinearLayout>

The only bitmap that I upload dynamically is userImage, I am using Glide to load it and I provide a fixed size of 64x64 DP converted to device pixels.

来源:https://stackoverflow.com/questions/56619566/android-transactiontoolargeexception-with-notificationmanager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!