gpt4 book ai didi

android推送通知显示空白内容

转载 作者:行者123 更新时间:2023-11-29 01:38:01 25 4
gpt4 key购买 nike

我在 android 中使用谷歌云消息传递显示警报。它在某些设备和模拟器中工作,但不适用于所有设备,如 Samsunng Galaxy Grand 和我的一些模拟器,它只显示图标和通知的标题,同时消息是空白的。

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

PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, MyActivity.class), 0);

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this).setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Siom Alert")//TITLE CAN BE TSKEN FROM HERE
.setStyle(new NotificationCompat.BigTextStyle().bigText(mes))
.setContentText(mes);

mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

最佳答案

试试这段代码。

 private void generateNotification(Context context, String message) {
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher, message, when);
String title = "New POC Alert";
Intent notificationIntent = new Intent(context, null);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;

// Play default notification sound
notification.defaults |= Notification.DEFAULT_SOUND;

// Vibrate if vibrate is enabled
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(0, notification);
}

//Mainfest权限

<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="vibrate" />

关于android推送通知显示空白内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26624437/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com