This example for you to share the Android message prompts the specific code for your reference, the details are as follows
protected Audiomanager Audiomanager;
protected vibrator Vibrator; Audiomanager = (Audiomanager) getsystemservice (Context.audio_service); This method is vibrator = (vibrator) getsystemservice (Context.vibrator_service) called by the context; Ditto/** * Vibrate and play tone */public void Vibrateandplaytone (Emmessage message) {if (System.currenttim
Emillis ()-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) {Lo
G.E ("TAG", "has been adjusted to mute");
Return
} long[] pattern = new Long[] {0, 180, 80, 120}; Vibrator.vibrate (Pattern,-1); Shake if (ringtone = = null) {Uri Notificationuri = Ringtonemanager.getdefaulturi (ringtonemanager.type_noti
fication); 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;
Ringtone.play (); For Samsung S3, we meet a bugs that the phone'll//continue ringtone without stop//SO add below Special handler to stop it after 3s if//needed if (vendor!= null && Vendor.tolowercase (). Co
Ntains ("Samsung")) {thread ctlthread = new Thread () {public void run () {try {
Thread.Sleep (3000);
if (ringtone.isplaying ()) {ringtone.stop ();
The catch (Exception e) {}}};
Ctlthread.run (); } catch (Exception e) {e.printstacktrAce ();
}
}
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.