ind*_*gga 6 android android-notifications
我正在实施以下通知.默认警报声音正常,但只有一次.我只想重复播放,直到水龙头注册.
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("I Am Fine")
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(NOTIFICATION_MESSAGE))
.setContentText(NOTIFICATION_MESSAGE)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
mBuilder.setSound(alarmSound,AudioManager.STREAM_MUSIC);
Run Code Online (Sandbox Code Playgroud)
setSound的第二个参数没有显示任何效果.请帮忙 !
Cod*_*ode 14
您必须使用FLAG_INSISTENT进行通知.从文件: -
public static final int FLAG_INSISTENT
将位按位进入标志字段,如果设置,将重复音频,直到取消通知或打开通知窗口.
常数值:4(0x00000004)
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Uri soundUri = RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
getApplicationContext()).setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("title").setContentText("message")
.setSound(soundUri); // This sets the sound to play
Notification mNotification = mBuilder.build();
mNotification.flags |= Notification.FLAG_INSISTENT;
// Display notification
notificationManager.notify(1, mNotification);
Run Code Online (Sandbox Code Playgroud)
Par*_*oor -2
您应该将通知声音静音,然后使用媒体播放器从应用程序播放声音文件。并将媒体播放器的实例设置为循环播放。
此后,您应该在通知中添加一个挂起的意图变量,一旦用户点击通知,就会触发关联的事件,您可以从这里停止媒体播放器实例。
| 归档时间: |
|
| 查看次数: |
5670 次 |
| 最近记录: |