【问题标题】:why toast message not showing in marshmallow 6.0.1 while showing it lower than 6.0为什么 toast 消息没有显示在棉花糖 6.0.1 中,而显示低于 6.0
【发布时间】: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


【解决方案1】:

我自己解决了我的问题,转到 来自移动设置的声音和通知。接下来,滚动到您要调整通知设置的应用程序。 启用它

【讨论】:

    【解决方案2】:

    试试这个,它在我的棉花糖手机上工作

    android.widget.Toast.makeText(getBaseContext(), "!! Message here !!",Toast.LENGTH_LONG).show();
    

    【讨论】:

    • 同样的结果...,
    猜你喜欢
    • 1970-01-01
    • 2019-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-12
    • 1970-01-01
    相关资源
    最近更新 更多