Android的通知声音声音、通知、Android

2023-09-12 06:56:22 作者:\仅此而已°

我用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);
 
android 设置整个app的通知栏Notification 的声音和震动用什么方法

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);