首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >提示通知按钮未执行

提示通知按钮未执行
EN

Stack Overflow用户
提问于 2016-12-25 09:29:28
回答 1查看 996关注 0票数 2

我已经找了几个小时了,但找不到解决问题的办法。有谁知道如何让提醒按钮调用广播吗?我的代码:

报警接收器通知生成器:

代码语言:javascript
复制
       NotificationCompat.Builder builder =
            new NotificationCompat.Builder(context)
                    .setSmallIcon(R.drawable.alarmicon)
                    .setContentTitle("Alarm for " + timeString)
                    .setContentText(MainActivity.alarmLabel.getText().toString())
                    .setDefaults(Notification.DEFAULT_ALL) // must requires VIBRATE permission
                    .setPriority(NotificationCompat.PRIORITY_HIGH); //must give priority to High, Max which will considered as heads-up notification

    //set intents and pending intents to call service on click of "dismiss" action button of notification
    Intent dismissIntent = new Intent(context, notificationButtonAction.class);
    dismissIntent.setAction(DISMISS_ACTION);
    PendingIntent piDismiss = PendingIntent.getBroadcast(context, 0, dismissIntent, 0);
    builder.addAction(R.drawable.alarmoff, "Dismiss", piDismiss);

    //set intents and pending intents to call service on click of "snooze" action button of notification
    Intent snoozeIntent = new Intent(context, notificationButtonAction.class);
    snoozeIntent.setAction(SNOOZE_ACTION);
    PendingIntent piSnooze = PendingIntent.getBroadcast(context, 0, snoozeIntent, 0);
    builder.addAction(R.drawable.snooze, "Snooze", piSnooze);

    // Gets an instance of the NotificationManager service
    NotificationManager notificationManager =
            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    //to post your notification to the notification bar with a id. If a notification with same id already exists, it will get replaced with updated information.
    notificationManager.notify(0, builder.build());

notificationButtonAction:

代码语言:javascript
复制
public static class notificationButtonAction extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        System.out.println("notificationButtonAction Started");
        String action = intent.getAction();
        if (SNOOZE_ACTION.equals(action)) {
            stopAlarm();
            System.out.println("Alarm Snoozed");
            MainActivity ma = new MainActivity();
            ma.setAlarm(true);
        }
        else if (DISMISS_ACTION.equals(action)) {
            stopAlarm();
            System.out.println("Alarm Dismissed");
        }
    }
}

我在notificationButtonAction中的打印行不打印,甚至连"notificationButtonAction开始“都不打印。

我遵循了简明软件(http://www.brevitysoftware.com/blog/how-to-get-heads-up-notifications-in-android/)的教程,但他们的代码似乎不起作用。

任何帮助都是非常感谢的!谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-23 19:44:51

结果,我没有把这个类添加到舱单上。我的密码很好。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41320011

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档