why notifications are collapsed in kitkat

时光毁灭记忆、已成空白 提交于 2021-01-29 06:05:27

问题


I was building a custom notification using the notification builder provide by android and am trying to use a custom notification. The following is the code used:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        RemoteViews remoteViews = new RemoteViews(getPackageName(),R.layout.resource_file);
        createNotificationChannel();
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID);
        builder.setSmallIcon(R.drawable.ic_launcher_background)
                .setContentTitle("mTitle")
                .setContentText("Some text that I have written for larger con" +
                        " I have written for larger content")
                .setCustomBigContentView(remoteViews)
                .setPriority(NotificationCompat.PRIORITY_DEFAULT);
        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
        notificationManager.notify(notificationID, builder.build());
    }


    private void createNotificationChannel() {
        // Create the NotificationChannel, but only on API 26+ because
        // the NotificationChannel class is new and not in the support library
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            CharSequence name = getString(R.string.channel_name);
            String description = getString(R.string.channel_description);
            int importance = NotificationManager.IMPORTANCE_DEFAULT;
            NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
            channel.setDescription(description);
            // Register the channel with the system; you can't change the importance
            // or other notification behaviors after this
            NotificationManager notificationManager = getSystemService(NotificationManager.class);
            notificationManager.createNotificationChannel(channel);
        }
    }  

The layout used for remoteViews is as:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout

    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:orientation="vertical"
    >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="I have some text that I want to display"
        android:padding="5dp"
        />

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="25dp"
        android:src="@drawable/ic_launcher_background"
        android:scaleType="fitXY"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="I have some text that I want to display"
        android:padding="5dp"
        />



</LinearLayout>   

On Kitkat 4.4.2 in my emulator the notfication appears as expected as:

but on Kitkat 4.4.4 the notification doesn't expand beyond that small section no matter how much I set the size of the remoteViews's parent LinearLayout:

Is there a way to force the expansion or is this a bug in this version of Kitkat?(Device is samsung galaxy core prime)

来源:https://stackoverflow.com/questions/60872286/why-notifications-are-collapsed-in-kitkat

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