【发布时间】:2016-10-16 07:31:33
【问题描述】:
我正在使用 toast 消息传递; toast 消息显示远低于 marshmallow 6.0,但对于 marshmallow 6.0 和 6.+ toast 未显示,推送通知也未显示。请解决这个问题。
吐司:
Toast.makeText(context, "You can use this service once between every 8 hours", Toast.LENGTH_LONG).show();
对于推送通知:
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
mBuilder.setSmallIcon(R.drawable.ic_warning_24dp).setContentTitle("Friends in danger").setContentText("Save friends in danger.");
//Intent resultIntent=new Intent(context,DangerFriendsMapsActivity.class);
TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
taskStackBuilder.addParentStack(DangerFriendsMapsActivity.class);
taskStackBuilder.addNextIntent(toDangerIntent);
PendingIntent pendingIntent = taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(pendingIntent);
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
mBuilder.setSound(alarmSound);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, mBuilder.build());
【问题讨论】:
-
我尝试过的结果相同
-
是所有toasts都没有显示还是只有这个?
-
@madhankumar
this是一个上下文。不要使用getBaseContext(),除非你完全理解它的作用。而且这里不是使用它的地方。 -
Notification 是一个 UI 元素。 推送通知或推送消息是一种传输方式。如果既没有显示 toast 也没有显示通知,这意味着您的代码到目前为止还没有执行。 IE。您的吐司和通知是正确的。问题在于应该触发 toast 或通知的事件。
-
在运行 api 23 时没有 toast 或通知未显示在应用程序中,但在低于 23 时运行良好。@greenapps EugenPechanec
标签: android