Android:创建持续闹钟(例如:早晨闹钟、来电)

发布于 2024-10-14 19:03:33 字数 630 浏览 8 评论 0原文

我正在编写一个基于警报的应用程序,并且正在寻找一种方法来坚持唤醒用户。理想情况下,我希望手机能够振动、响铃并显示消息。我尝试了几种不同的选项,这就是我目前所拥有的:

  • 让后台服务启动一个振动和振动的活动。播放音乐。

    <块引用>

    问题:即使使用 WAKE_LOCK,用户似乎仍然需要打开屏幕并解锁才能查看我的活动

  • 使用 AlarmManager 与 RTC_WAKEUP 和广播接收器来启动上述活动

    <块引用>

    同样的问题

  • 只需弹出一个通知,用户可以单击该通知来查看活动

    <块引用>

    问题:仍然是同样的问题,而且我也无法收到振动和响铃的通知,并且经常重复直到被取消

我真正想要的是具有类似于基本 Android 早上闹钟或类似于接听电话的行为通话:无论您的手机处于唤醒还是睡眠状态,它都会响铃、振动并显示消息、照片等信息...

任何有关使用方向的提示将不胜感激!我确信我见过闹钟应用程序或“假电话”应用程序做类似的事情,但我没有主意。

干杯

ps:在这个应用程序的上下文中,我认为以这种方式唤醒用户是合理的。谨慎的通知是不合适的 - 除非你可以被一次振动唤醒:)

I'm writing an alarm-based application, and I'm looking for a way to wake up the user insistently. Ideally, I'd like the phone to vibrate, ring, and display a message. I tried a few different options, here's what I have for the moment:

  • Have the background service start an activity that vibrates & plays music.

    problem: even with a WAKE_LOCK, it seems that the user still has to turn on the screen and unlock it to see my activity

  • Use the AlarmManager with RTC_WAKEUP and a broadcast receiver to start the aforementioned activity

    same issue

  • Simply pop up a notification, which the user can click to see the activity

    problem: stil the same issue, and also I can't get the notification to vibrate and ring, and repeat often until dismissed

What I would really like is to have a behaviour similar to the basic Android morning alarm, or similar to receiving a phone call: regardless of whether your phone is awake or sleeping, it rings, vibrates and displays information such as a message, a photo...

Any tips on the direction to use would be greatly appreciated! I'm sure I've seen alarm apps or "fake phone call" apps do something similar, but I'm out of ideas.

Cheers

ps: in the context of this application, I think it would be reasonable to wake up the user this way. A discreet notification would not be appropriate - unless you can wake up to a single vibration :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断舍离 2024-10-21 19:03:33

您查看过 ACQUIRE_CAUSES_WAKEUP 标志吗?看起来它应该做你想做的事。请参阅此处了解更多信息: http://developer.android.com/reference/android /os/PowerManager.html

Have you looked at the ACQUIRE_CAUSES_WAKEUP flag? It looks like it should do what you want. See here for more information: http://developer.android.com/reference/android/os/PowerManager.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文