Android下 当 notification弹出时,有两种方法可以播放提示音


方法一:

private void soundRing(Context context) throws IllegalArgumentException, SecurityException, IllegalStateException, IOException{MediaPlayer mp = new MediaPlayer();mp.reset();mp.setDataSource(context,RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));mp.prepare();mp.start();}

这种方法需要加try catch


方法二:

NotificationManager nm = (NotificationManager)context.getSystemService(android.content.Context.NOTIFICATION_SERVICE);Uri ringUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);        Notification noti = new NotificationCompat.Builder(context)        .setTicker(name+": " + msg)        .setContentTitle(name)        .setContentText(msg)        .setSmallIcon(R.drawable.ic_launcher)        .setContentIntent(pIntent)        .setSound(ringUri)        .build();        nm.notify(MmsConfig.NOTIFY_ID, noti);
主要是setSound(ringUri)


======================================

如果文章对您有用,请 评论 支持下!! ^ ^

如果转载文章,请注明出处 。谢谢!!
宿莽 csdn

更多相关文章

  1. Android程序设置成横屏方法
  2. 用于做 Android(安卓)屏幕自适应的文章资源
  3. android 开发积累
  4. android 开发中将十六进制 颜色代码 转换为int类型数值 方法 :
  5. Fragment总结
  6. http://dl-ssl.google.com/android上不去解决方案
  7. 详解Android读取本地图片和网络图片的方法
  8. android onSaveInstanceState的使用方法
  9. Android中全屏无标题设置

随机推荐

  1. 多媒体内容理解在美图社区的应用实践
  2. 详谈pg逻辑复制系列之逻辑复制的搭建(二)
  3. 机器人的眼睛,需要一个Spartan-6 FPGA
  4. 数据驱动的京东精细化消费者运营平台
  5. Opal Kelly公司推出面向FPGA模块的SYZYGY
  6. 移动商城首页的页眉和页脚的布局和flex项
  7. 第三课 选择器、模块化组件、伪类选择
  8. CSS盒模型以及CSS定位
  9. flex项目属性,实战案例。
  10. oracle 还原点(restore point)