开发者

android alert with sound, vibration

I need to add an alerting system to my application. When some data is read i need to alert the user of the data. I need a dialog to pop up letting the user know the time it occurred and tell them some other stuff. The user needs to click ok and that is it. Just to bring their attention to something. I need it to make noise and vibrate. I was looking into notifications and alertdialogs. AlertDialog seems to be what i want, however, i do not see anything about sounds and vibrations in the documentation for alertdialog. Is there noise and vibration for alertdialog? Or is there another way for开发者_StackOverflow中文版 me to do this with sounds and vibration? I need the window to stay active until the user presses ok.

Thanks!


I can't help you with the sound part but the Vibrate is easy:

Vibrator vibrator;
vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(500);

You also need the permission in the manifest.

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


For vibration there is a separate class which you have to implement. See this.

And another way is for noise is to use audiomanager or mediaplayer to play your sound.


This is a very simple way for vibrating your device.

import android.os.Vibrator;

 ...

 Vibrator v = (Vibrator) this.context.getSystemService(Context.VIBRATOR_SERVICE);
 // Vibrate for 500 milliseconds
 v.vibrate(500);

Note:

Don't forget to include permission in AndroidManifest.xml file:

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜