java - 即使设置为通知也不会播放声音或显示灯光

标签 java android audio notifications

在我的 android 应用程序中,我有以下代码:

Notification notification = new Notification(icon, tickerText, when);

        context = context.getApplicationContext();
        CharSequence contentTitle = "UK Radio Guide";

        CharSequence contentText = title + " on " + channel_id + " at " + start;

        Intent notificationIntent = new Intent(context, ViewSchedules.class);
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

        notification.ledARGB = 0xff00ff00;
        notification.ledOnMS = 300;
        notification.ledOffMS = 1000;
        notification.flags |= Notification.FLAG_SHOW_LIGHTS;



        notification.sound = Uri.parse("android.resource://com.robinwilson.radioguide/" +R.raw.chimes);
        notification.vibrate = new long[] { 0, 300, 200, 300, 400, 300 };

        // Actually send the notification
        nm.notify(0, notification);

据我所知,我已按照文档中的步骤将其设置为播放资源文件夹中的声音,并使灯光闪烁。然而,这些都没有发生。但是,它会按照指示振动。

知道我在这里做错了什么吗?我查看了我可以在 AndroidManifest.xml 文件中授予该应用程序的权限,但我看不到允许它闪烁或发出声音的权限。

最佳答案

我假设你有

NotificationManager nm = ( NotificationManager ) getSystemService( NOTIFICATION_SERVICE );

在我尝试之前我没有答案,但我之前有我的闪光灯 LED。我建议您一次尝试一件(LED/声音/振动)。

关于java - 即使设置为通知也不会播放声音或显示灯光,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2709927/

相关文章:

java - 如何更改 Java 9 中的包装类初始化?

java - 如何使用 Java + ChromeDriver 在 AWS Lambda 中运行 Google Chrome 以进行 Selenium 测试

android - 如何在 Android 中打开 Instagram 的相机?

javascript - 提高 socket io 中的音质,将音频数据从客户端发送到服务器返回客户端

ios - AVAudioRecorder 录制 AAC/m4a

Java声音API : Attempt to Do Live Microphone Input Monitoring is Slow

java - application.properties 中当前项目位置引用变量

java - 呈现模板gsp时通过model属性检索传递的数据时缺少MissingMethodException

java - Android (Java) JSON 被发送到服务器,但里面的数据不是 "seeing",而是对象的 toString

android - 如何防止双击按钮重复操作?