android 震动和提示音的实现代码
程序员文章站
2024-01-16 21:24:22
android的消息提示(震动和提示音),实现代码如下所示:
public class vibratorutil {
protected audiomanager...
android的消息提示(震动和提示音),实现代码如下所示:
public class vibratorutil { protected audiomanager audiomanager; protected vibrator vibrator; private ringtone ringtone; private static final int min_time_out = 4000; //时间间隔 long lastnotificationtime; public vibratorutil() { audiomanager = (audiomanager) myapp.getcontext().getsystemservice(context.audio_service); //此方法是由context调用的 vibrator = (vibrator) myapp.getcontext().getsystemservice(context.vibrator_service); //同上 } /** * 开启手机震动和播放系统提示铃声 */ public void vibrateandplaytone() { if (system.currenttimemillis() - lastnotificationtime < min_time_out) { return; } try { lastnotificationtime = system.currenttimemillis(); if (audiomanager.getringermode() == audiomanager.ringer_mode_silent) { return; } long[] pattern = new long[]{0, 180, 80, 120}; vibrator.vibrate(pattern, -1); //震动 if (ringtone == null) { uri notificationuri = ringtonemanager.getdefaulturi(ringtonemanager.type_notification); ringtone = ringtonemanager.getringtone(myapp.getcontext(), notificationuri); if (ringtone == null) { return; } } if (!ringtone.isplaying()) { ringtone.play(); //判断手机品牌 string vendor = build.manufacturer; 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) { } } }; ctlthread.run(); } } } catch (exception e) { e.printstacktrace(); } } }
总结
以上所述是小编给大家介绍的android 震动和提示音的实现代码,希望对大家有所帮助
推荐阅读
-
android 震动和提示音的实现代码
-
Android 进度条自动前进效果的实现代码
-
Android 使用 Scroller 实现平滑滚动功能的示例代码
-
Android实现强制下线功能的示例代码
-
Android实现发送短信的小程序示例代码
-
Flutter 和 Android 互相传递数据的实现
-
php实现的DateDiff和DateAdd时间函数代码分享
-
PHP获取客户端真实IP地址的5种情况分析和实现代码_php实例
-
Android AutoCompleteTextView和MultiAutocompleteTextView实现动态自动匹配输入的内容
-
哪位大神会用PHP代码实现赞的功能和回复的功能啊该如何解决