让android中的通知不会崩溃

让android中的通知不会崩溃,android,kotlin,android-notifications,Android,Kotlin,Android Notifications,我想要一个通知,它总是保持在扩展模式,当用户尝试这样做时不会崩溃 我试着设置: setCustomContentView(null)甚至不调用前一个函数。 我还尝试了所有可能的游戏,使用了NotificationBuilder的其他方法,但没有成功 有人能建议如何实现上述目标吗?相反,这很容易做到,但这将需要一些黑客 可扩展通知是通知的特例。如果大视图不在通知抽屉的顶部,则显示为“已关闭”,可通过滑动进行扩展。引用安卓开发者的话: 只有当通知展开时,通知的大视图才会出现,这发生在通知位于通知抽屉

我想要一个通知,它总是保持在扩展模式,当用户尝试这样做时不会崩溃

我试着设置:
setCustomContentView(null)
甚至不调用前一个函数。 我还尝试了所有可能的游戏,使用了
NotificationBuilder
的其他方法,但没有成功


有人能建议如何实现上述目标吗?相反,这很容易做到,但这将需要一些黑客

可扩展通知是通知的特例。如果大视图不在通知抽屉的顶部,则显示为“已关闭”,可通过滑动进行扩展。引用安卓开发者的话:

只有当通知展开时,通知的大视图才会出现,这发生在通知位于通知抽屉的顶部时,或者当用户用手势展开通知时。从Android 4.1开始,可以使用扩展通知


我的要求正好相反!这是显而易见的
String  someLongText="here is your long text",channelId="default"; 
Bitmap icon1 = BitmapFactory.decodeResource(getResources(),
                R.mipmap.ic_launcher);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
            getApplicationContext()).setAutoCancel(true)
            .setContentTitle("Exemplo 1")
            .setChannelId (channelId)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setLargeIcon(icon1).setContentText("Hello World!");

    NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
    bigText.bigText(someLongText);
    bigText.setBigContentTitle("Hello world title");
    bigText.setSummaryText("Hello world summary");
    mBuilder.setStyle(bigText);
    mBuilder.setPriority(NotificationCompat.PRIORITY_MAX);

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent (getApplicationContext(),
            MainActivity.class);

    // The stack builder object will contain an artificial back
    // stack for
    // the
    // started Activity.
    // getApplicationContext() ensures that navigating backward from
    // the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder
            .create(getApplicationContext());

    // Adds the back stack for the Intent (but not the Intent
    // itself)
    stackBuilder.addParentStack(MainActivity.class);

    // Adds the Intent that starts the Activity to the top of the
    // stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder
            .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    // mId allows you to update the notification later on.
    mNotificationManager.notify(100, mBuilder.build());