Wat*_*son 7 android android-notifications
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(ns);
int icon = R.drawable.ic_launcher;
CharSequence tickerText = title;
long when = System.currentTimeMillis();
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
if(alarmSound == null){
alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
if(alarmSound == null){
alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
}
}
Intent intent = new Intent();
PendingIntent pendingIntent
= PendingIntent.getActivity(this, 0, intent, 0);
NotificationCompat.BigTextStyle bigxtstyle =
new NotificationCompat.BigTextStyle();
bigxtstyle.bigText(text);
bigxtstyle.setBigContentTitle(title);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setStyle(bigxtstyle)
.setSmallIcon(icon)
.setAutoCancel(true)
.setSound(alarmSound)
.setDeleteIntent(pendingIntent)
.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(), 0));
Notification noti = mBuilder.build();
mNotificationManager.notify(notificationid++, noti);
Run Code Online (Sandbox Code Playgroud)
此代码有效,并显示通过自动换行宣传的文本.但是,当后续通知发生时,先前的通知会丢失其文本.有人可以帮忙解决这个问题吗?它可能是我设置不正确的东西,我是android apis的新手.
Flo*_*ern 11
Android默认情况下仅显示一个展开的通知.您的通知不会丢失其内容,只会被压缩并仅显示正常的单行内容.但似乎您没有指定此内容,因此压缩通知为空.
您可以使用setContentTitle()和setContentText()设置单行文本.
| 归档时间: |
|
| 查看次数: |
5335 次 |
| 最近记录: |