Android message alert (vibrate and beep)

Source: Internet
Author: User

 protectedAudiomanager Audiomanager;protectedvibrator Vibrator; Audiomanager=(Audiomanager) Getsystemservice (Context.audio_service); //This method is called by the context vibrator=(Vibrator) Getsystemservice (Context.vibrator_service); //Ibid  ./*** Vibrate and play tone*/     Public voidvibrateandplaytone (Emmessage message) {if(System.currenttimemillis ()-Lastnotifiytime < 1000) {            //received 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", "has been muted"); return; } Long[] pattern =New Long[] {0, 180, 80, 120 }; Vibrator.vibrate (Pattern,-1); //Vibration if(Ringtone = =NULL) {Uri Notificationuri=Ringtonemanager.getdefaulturi (ringtonemanager.type_notification); Ringtone=Ringtonemanager.getringtone (AppContext, Notificationuri); if(Ringtone = =NULL) {log.d (TAG,"Cant find ringtone at:" +Notificationuri.getpath ()); return; }
} if(!ringtone.isplaying ()) { //string vendor = Build.manufacturer; (); //for Samsung S3, we meet a bugs that the phone would//continue ringtone without stop//So add below special handler-stop it after 3s if//needed if (vendor! = null && vendor.tolowercase (). Contains ("Samsung")) {Thread Ctlthread = new Thread () {public void run () {try { Thread.Sleep (3000); if (ringtone.isplaying ()) {ringtone.stop (); }} catch (Exception e) {}}; (); } } Catch(Exception e) {e.printstacktrace (); } }

Android message alert (vibrate and beep)

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: 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.