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(