当前位置: 首页 > news >正文

android 广播震动,android的消息提示(震动与提示音)

protectedAudioManager audioManager;protectedVibrator vibrator;

audioManager=(AudioManager)getSystemService(Context.AUDIO_SERVICE); //此方法是由Context调用的 vibrator=(Vibrator)getSystemService(Context.VIBRATOR_SERVICE); //同上/*** 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","已经调成静音");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(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 bug that the phone will//continue ringtone without stop//so add below special handler to 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) {

}

}

};

ctlThread.run();

}

}catch(Exception e) {

e.printStackTrace();

}

}

相关文章:

  • android 动态创建线程池,Android四种常见的线程池
  • android包之间的关系,第 4 章 依赖关系,Android 库和多项目设置
  • android数组的定义数组长度,Android OpenGLES3.0 入门教程(三)——顶点数组和统一变量...
  • android mediastore.images.media.insertimage,尝试获取图像URI时,mediastore.images.media.insertImage返回空值...
  • android程序拍照内存溢出,彻底解决Android 拍照 内存溢出 Out of Memory的问题
  • 华为1120发布鸿蒙战略,华为发布智慧屏战略 首款产品搭载鸿蒙系统
  • Android备忘录github,Github备忘录
  • lua android异常捕获,使用lua实现try-catch异常捕获
  • 弹出自动消失html,用JS实现弹出div层过2秒自动消失的效果
  • html5主题标记是那个,网页文件主体标记 index.html是什么文件
  • html5走格子游戏,JS/HTML5游戏常用算法之碰撞检测 地图格子算法实例详解
  • html导航栏点击显示该栏内容,点击导航栏,实现下方内容改变
  • html 安卓 web 页面布局,webApp 页面布局
  • 学 HTML5 开发 零基础 经验,零基础能不能学会HTML5开发技术?
  • html表示dom怎么设置,{HTML5}DOM 和 CSS 操作-第二节-设置元素及内容
  • 0基础学习移动端适配
  • exports和module.exports
  • JavaScript 事件——“事件类型”中“HTML5事件”的注意要点
  • Js基础知识(四) - js运行原理与机制
  • PHP变量
  • python学习笔记-类对象的信息
  • RedisSerializer之JdkSerializationRedisSerializer分析
  • Sass Day-01
  • SSH 免密登录
  • 翻译--Thinking in React
  • 如何在 Tornado 中实现 Middleware
  • 使用Envoy 作Sidecar Proxy的微服务模式-4.Prometheus的指标收集
  • 找一份好的前端工作,起点很重要
  • No resource identifier found for attribute,RxJava之zip操作符
  • 带你开发类似Pokemon Go的AR游戏
  • #if #elif #endif
  • $emit传递多个参数_PPC和MIPS指令集下二进制代码中函数参数个数的识别方法
  • (04)odoo视图操作
  • (1/2)敏捷实践指南 Agile Practice Guide ([美] Project Management institute 著)
  • (2021|NIPS,扩散,无条件分数估计,条件分数估计)无分类器引导扩散
  • (附源码)计算机毕业设计SSM智能化管理的仓库管理
  • (力扣记录)1448. 统计二叉树中好节点的数目
  • (强烈推荐)移动端音视频从零到上手(上)
  • (十二)devops持续集成开发——jenkins的全局工具配置之sonar qube环境安装及配置
  • *++p:p先自+,然后*p,最终为3 ++*p:先*p,即arr[0]=1,然后再++,最终为2 *p++:值为arr[0],即1,该语句执行完毕后,p指向arr[1]
  • ... fatal error LINK1120:1个无法解析的外部命令 的解决办法
  • .class文件转换.java_从一个class文件深入理解Java字节码结构
  • .net mvc部分视图
  • :“Failed to access IIS metabase”解决方法
  • @EnableWebMvc介绍和使用详细demo
  • @serverendpoint注解_SpringBoot 使用WebSocket打造在线聊天室(基于注解)
  • @拔赤:Web前端开发十日谈
  • [AndroidStudio]_[初级]_[修改虚拟设备镜像文件的存放位置]
  • [C++] 默认构造函数、参数化构造函数、拷贝构造函数、移动构造函数及其使用案例
  • [Dxperience.8.*]报表预览控件PrintControl设置
  • [hdu2196]Computer树的直径
  • [java基础揉碎]关系运算符(比较运算符)逻辑运算符赋值运算符三元运算符运算符的优先级
  • [node] Node.js的全局对象Global
  • [Redis]Redis的数据类型
  • [RISC-V]verilog