【Android】播放提示音
16lz
2021-12-04
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
更多相关文章
- Android程序设置成横屏方法
- 用于做 Android(安卓)屏幕自适应的文章资源
- android 开发积累
- android 开发中将十六进制 颜色代码 转换为int类型数值 方法 :
- Fragment总结
- http://dl-ssl.google.com/android上不去解决方案
- 详解Android读取本地图片和网络图片的方法
- android onSaveInstanceState的使用方法
- Android中全屏无标题设置