[英]Making notification in android not collapse
我想要一个始终保持展开模式并且在用户尝试这样做时不会折叠的通知。
我尝试设置: setCustomContentView(null)
甚至不调用以前的 function。 我还尝试了所有可能的NotificationBuilder
其他方法,但无济于事!
有人可以建议如何实现上述目标吗? 反过来很容易做到,但这需要一些 hack imo!
可扩展的 Notification 是 Notification 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());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.