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