闹钟响起时如何播放默认手机铃声?

发布于 2024-09-08 08:39:48 字数 79 浏览 2 评论 0原文

我已经编写了设置闹钟的代码。当时间流逝时,我能够从我的警报接收器类中成功举杯。

现在我想播放默认手机铃声并振动手机。 我该怎么做

i have written the code for setting an alarm. I am able to raise a toast successfully from my alarm receiver class when the time ticks off.

Now i want to play the default mobile tone as well as vibrate thee phone.
How do i do that

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

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

发布评论

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

评论(2

话少情深 2024-09-15 08:39:48

这是一个可以帮助您的示例

Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.flags |= Notification.FLAG_AUTO_CANCEL;

notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.ledARGB = 0xff00ff00;
notification.ledOnMS = 300;
notification.ledOffMS = 1000;

您需要将振动权限添加到清单文件中。

<uses-permission
        android:name="android.permission.VIBRATE"></uses-permission>

Here is a sample that will help you

Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.flags |= Notification.FLAG_AUTO_CANCEL;

notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.ledARGB = 0xff00ff00;
notification.ledOnMS = 300;
notification.ledOffMS = 1000;

You will need to add Vibrate permission to your manifest file.

<uses-permission
        android:name="android.permission.VIBRATE"></uses-permission>
对你的占有欲 2024-09-15 08:39:48

为了播放手机铃声,您可以使用广播接收器中的媒体播放器实例,

 mediaPlayer = MediaPlayer.create(context, R.raw./*your ringtone here*/);
     mediaPlayer.start();

您可以在此处传递上下文,但不能传递“this”

for playing mobile tone you can use the media player instance in the broadcast receiver

 mediaPlayer = MediaPlayer.create(context, R.raw./*your ringtone here*/);
     mediaPlayer.start();

here you pass context but not "this"

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