Android message prompts (vibrations and prompts), android

Source: Internet
Author: User

Android message prompts (vibrations and prompts), android

Protected AudioManager; protected Vibrator vibrator; audioManager = (audioManager) getSystemService (Context. AUDIO_SERVICE); // this method is called by the Context vibrator = (Vibrator) getSystemService (Context. VIBRATOR_SERVICE); // same as above/*** vibrate and play tone */public void vibrateAndPlayTone (EMMessage message) {if (System. currentTimeMillis ()-lastNotifiyTime <1000) {// encoded ed new messages within 2 seconds, skip play ringtone return;} try {lastNotifiyTime = System. currentTimeMillis (); // check if in silent mode if (audioManager. getRingerMode () = AudioManager. RINGER_MODE_SILENT)
{
Log. e ("TAG", "mute"); return;} long [] pattern = new long [] {0,180, 80,120}; vibrator. vibrate (pattern,-1); // shake if (ringtone = null) {Uri icationicationuri = RingtoneManager. getDefaultUri (RingtoneManager. TYPE_NOTIFICATION); ringtone = RingtoneManager. getRingtone (appContext, icationicationuri); if (ringtone = null) {Log. d (TAG, "cant find ringtone at:" + icationicationuri. getPath (); return ;}
} If (! Ringtone. isPlaying () {// String vendor = Build. MANUFACTURER; ringtone. play (); // for samsung S3, we meet a bug that the phone will // continue ringtone without stop // so add below special handler to stop it after 3 s if // needed if (vendor! = Null & vendor. toLowerCase (). contains ("samsung") {Thread ctlThread = new Thread () {public void run () {try {Thread. sleep (1, 3000); if (ringtone. isPlaying () {ringtone. stop () ;}} catch (Exception e) {}}; ctlThread. run () ;}} catch (Exception e) {e. printStackTrace ();}}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.