我正在我的应用程序中实现Google Cloud Messaging.服务器代码还没有准备好,在我的环境中由于一些防火墙限制,我无法为推送通知部署测试服务器.我正在寻找的是一个在线服务器,它会向我的设备发送一些测试通知来测试我的客户端实现.
android server-push push-notification android-notifications google-cloud-messaging
我只收到一个通知,如果有另一个通知,它将替换前一个通知,这是我的代码
private static void generateNotification(Context context, String message,
String key) {
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
String title = context.getString(R.string.app_name);
Intent notificationIntent = new Intent(context,
FragmentOpenActivity.class);
notificationIntent.putExtra(key, key);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_SOUND;
// notification.sound = Uri.parse("android.resource://" + …Run Code Online (Sandbox Code Playgroud) Android 4.1为用户提供了一个复选框,用于禁用特定应用程序的通知.
但是,作为开发人员,我们无法知道对通知的调用是否有效.
我真的需要检查当前应用程序是否禁用了通知,但我在API中找不到任何设置.
有没有办法在代码中检查此设置?
我的应用程序显示了一些通知,并且根据用户首选项,它可能会在通知中使用自定义布局.它运作良好,但有一个小问题 - 文本颜色.股票Android和几乎所有制造商皮肤都使用黑色文本作为通知文本的浅色背景,但三星没有:他们的通知下拉具有深色背景,默认通知布局中的文本是白色.
所以这会导致一个问题:不使用任何花哨布局的通知显示正常,但使用自定义布局的通知很难阅读,因为文本是黑色而不是默认白色.即使官方文档只是#000为a 设置颜色TextView,所以我找不到任何指针.
用户很友好地截取问题的屏幕截图:

那么如何在布局中使用设备中的默认通知文本颜色?我宁愿不开始根据手机型号动态改变文本颜色,因为这需要大量更新,而定制ROM的人可能仍会遇到问题,具体取决于他们使用的皮肤.
我正在通过通知设计模式,并没有找到任何谈论通知图标背景.您可能已经注意到,自定义通知只有浅灰色背景.但是环聊等应用或简单的USB调试通知都会为其通知图标背景提供自定义颜色.
有没有可能将那种灰色变成其他东西?(以编程方式显示特定圆圈的颜色)

任何人都知道我们如何以编程方式从应用程序中删除使用Pending intent调用的通知.
我曾经使用以下方法取消通知.
AlarmManager am=(AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(Display.this, TwoAlarmService.class);
PendingIntent pi = PendingIntent.getBroadcast(Display.this, AlarmNumber, intent, PendingIntent.FLAG_CANCEL_CURRENT);
am.cancel(pi);
Run Code Online (Sandbox Code Playgroud)
但问题是已经解雇的通知没有从通知栏中删除.
提前致谢...

notifications android android-notifications android-pendingintent
某些应用程序的通知无法通过滑动来解除.
我该如何管理这种行为?
我没有看到任何有关如何使用NotificationCompat与Android O的信息 Notification Channels
我确实看到一个新的构造函数,它接受一个channelId但是如何获取Compat通知并在NotificationChannel中使用它,因为createNotificationChannel它需要一个NotificationChannel对象
我需要创建一个简单的通知,如果可能的话,它会与声音和图标一起显示在通知栏中?我还需要它与Android 2.2兼容,所以我发现NotificationCompat.Builder适用于4以上的所有API.如果有更好的解决方案,请随意提及.
notifications android android-notifications android-notification-bar