Android的通知声音 [英] Android Notification Sound

查看:461
本文介绍了Android的通知声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用NotificationCompat建设者的更新,我不能得到通知发出声音。它会震动和闪烁的灯光。 Android的文件说,设定一个风格,我这样做:

  builder.setStyle(新NotificationCompat.InboxStyle());
 

但没有声音?

满code:

  NotificationCompat.Builder建设者=
        新NotificationCompat.Builder(本)
        .setSmallIcon(R.drawable.ic_launcher)
        .setContentTitle(通知示例)
        .setContentText(这是一个测试通知);


意图notificationIntent =新的意图(这一点,MenuScreen.class);

PendingIntent contentIntent = PendingIntent.getActivity(此,0,notificationIntent,
        PendingIntent.FLAG_UPDATE_CURRENT);

builder.setContentIntent(co​​ntentIntent);
builder.setAutoCancel(真正的);
builder.setLights(Color.BLUE,500,500);
长[]模式= {500,500,500,500,500,500,500,500,500};
builder.setVibrate(图案);
builder.setStyle(新NotificationCompat.InboxStyle());
//添加为通知
NotificationManager经理=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(1,builder.build());
 

解决方案

什么是从我的previous code丢失:

 乌里alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
builder.setSound(alarmSound);
 

I've used the newer NotificationCompat builder and I can't get the notification to make a sound. It will vibrate and flash the light. The android documentation says to set a style which I've done with:

  builder.setStyle(new NotificationCompat.InboxStyle());

But no sound?

The full code:

NotificationCompat.Builder builder =  
        new NotificationCompat.Builder(this)  
        .setSmallIcon(R.drawable.ic_launcher)  
        .setContentTitle("Notifications Example")  
        .setContentText("This is a test notification");  


Intent notificationIntent = new Intent(this, MenuScreen.class);  

PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,   
        PendingIntent.FLAG_UPDATE_CURRENT);  

builder.setContentIntent(contentIntent);  
builder.setAutoCancel(true);
builder.setLights(Color.BLUE, 500, 500);
long[] pattern = {500,500,500,500,500,500,500,500,500};
builder.setVibrate(pattern);
builder.setStyle(new NotificationCompat.InboxStyle());
// Add as notification  
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);  
manager.notify(1, builder.build());  

解决方案

What was missing from my previous code:

Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
builder.setSound(alarmSound);

这篇关于Android的通知声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆