【问题标题】:Android Notification vibration timeAndroid 通知振动时间
【发布时间】:2023-03-16 03:48:02
【问题描述】:

我正在使用以下代码进行通知。它应该在事件发生时振动并发出声音。但是在创建通知时它会发出声音,尽管通知时间是在 30 分钟之后。

final Notification notifyDetails = new Notification(R.drawable.icon, "Myapp",nextAlarmTime);
Context context = getApplicationContext();
CharSequence contentTitle = "Viramune";
CharSequence contentText = notificationAlart;

Intent notifyIntent = new Intent(context, Myapp.class);
PendingIntent intent1 = PendingIntent.getActivity(ViewDoughnut.this, 0, notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent1);


notifyDetails.flags = Notification.FLAG_ONLY_ALERT_ONCE;
notifyDetails.defaults |= Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE;

mNotificationManager.notify((int) editEventid, notifyDetails);

我的代码有什么问题?

【问题讨论】:

    标签: android audio vibration notificationmanager


    【解决方案1】:

    Android 完全按照它的指示去做:

    mNotificationManager.notify((int) editEventid, notifyDetails);
    

    此行创建一个通知。您应该使用AlarmManager 来安排您以后的通知。

    【讨论】:

      【解决方案2】:
      1. Notification构造函数的第三个参数不是用来决定什么时候发出通知的,只是用来显示和排序的。
      2. 我相信您正在尝试做一些需要使用 AlarmManager 而不是 Notification 来完成的事情。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-03-09
        • 1970-01-01
        • 2017-01-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多