我想为通知设置一个自定义标题,但它总是在标题中设置项目名称。下面是我的代码。这段代码中有什么错误?
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("My Notification")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());发布于 2016-08-10 19:46:53
你在这里使用的是硬价值,.setContentTitle(getResources().getString(R.string.app_name))这就是为什么你总是看到相同的标题。
<string name="app_name">Your App Name</string>你可以使用一些变量的动态值来改变它。
发布于 2016-08-10 19:46:43
您将notif title设置为"My Notification"。将其更改为您的应用程序名称。
https://stackoverflow.com/questions/38872517
复制相似问题