在我的 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/