开发者

How to play default mobile tone when Alarm is fired?

i 开发者_JAVA技巧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


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>


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"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜