如何在需要时通知短信或通知用户 [英] How to notify a user with SMS or notification when needed

查看:129
本文介绍了如何在需要时通知短信或通知用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此​​,在我的应用我期待让学生课程表以及他们需要在课堂上的时间。

So in my app I'm looking to have the students class schedules and the times which they need to be in class.

当应用程序被关闭,我还是想通知弹出他们的阶级即将开始(可能震动)。

When the app is turned off I still want the notification to pop up that their class is about to start (possibly vibrate).

这样的功能非常类似于一个传入文本信息或类似的电子邮件通知。我想知道如何实现为一个应用程序?

This sort of functionality is very akin to an incoming text message or notification of something like an email. I was wondering how to implement that into an app?

推荐答案

您将需要使用的 AlarmManager 当您需要的通知,可能与的 RTC_WAKEUP 标志,以便将唤醒器件从睡眠。从你的警报接收器,你将需要采取唤醒锁定(如果使用RTC_WAKEUP),并开始将要使用的 NotificationManager 显示一条消息给用户(非常类似于接收到的SMS消息)。

You will need to use the AlarmManager to set an alarm when you require the notification, possibly with the RTC_WAKEUP flag so the device will wake from a sleep. From your alarm receiver you will need to take a wake lock (if you used RTC_WAKEUP) and start a service that will use the NotificationManager to display a message to the user (very similar to the incoming SMS message).

由于@WarrenFaith指出,您将需要创建一个BOOT_COMPLETED接收器重新建立报警后,他们不是持久的手机将重新启动。

As @WarrenFaith pointed out you will need to create a BOOT_COMPLETED receiver to re-establish the alarm after the phone is rebooted as they are not persistent.

这篇关于如何在需要时通知短信或通知用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆