在Android中发出通知不会崩溃

我想要一个始终处于扩展模式并且在用户尝试操作时不会折叠的通知。

我尝试设置: setCustomContentView(null)甚至不调用前一个函数。 我也尝试了用其他NotificationBuilder方法进行所有可能的游戏,但无济于事!

有人可以建议如何实现上述目标吗?反之很容易做到,但是这需要一些hack imo!

iquw330860503 回答:在Android中发出通知不会崩溃

可扩展通知是通知Big View的特例。如果“大视图”不在通知抽屉的顶部,则它显示为“已关闭”并且可以通过滑动扩展。来自Android开发人员的报价:

  

仅当展开通知时才会显示通知的大视图,这种情况发生在通知位于通知抽屉的顶部或用户使用手势展开通知时。从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());
本文链接:https://www.f2er.com/3104911.html

大家都在问