Tag: android notifications

Android:分组通知和摘要仍然分别显示在4.4和以下

我想在Android Wear上实施堆叠通知为此,我为每个“商品”创build了1个摘要通知和N个单独通知。 我只想要摘要在手机上显示。 这是我的代码: private void showNotifications() { NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); showNotification1(notificationManager); showNotification2(notificationManager); showGroupSummaryNotification(notificationManager); } private void showNotification1(NotificationManager notificationManager) { showSingleNotification(notificationManager, "title 1", "message 1", 1); } private void showNotification2(NotificationManager notificationManager) { showSingleNotification(notificationManager, "title 2", "message 2", 2); } protected void showSingleNotification(NotificationManager notificationManager, String title, String message, int notificationId) { NotificationCompat.Builder builder = new […]

可以从工作线程调用NoticationManager.notify()吗?

我的问题更多的是什么是一个好的做法,而不是可能的: 从工作线程调用NoticationManager.notify()是否是件好事? 无论如何,系统是否在UI线程中执行它? 我总是试着记住,关于UI的东西应该在UI线程中执行,其余的在工作线程中执行,正如关于进程和线程的Android文档所build议的: 另外,Andoid UI工具包不是线程安全的。 所以,你不能从一个工作者线程操纵你的UI – 你必须从UI线程对你的用户界面进行所有的操作。 因此,Android的单线程模型只有两条规则: 不要阻塞UI线程 不要从UI线程之外访问Android UI工具包 然而,我对Android文档本身给出的一个例子感到惊讶( 关于通知的进展情况),其中一个持续的通知进度直接从工作者线程更新: mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mBuilder = new NotificationCompat.Builder(this); mBuilder.setContentTitle("Picture Download") .setContentText("Download in progress") .setSmallIcon(R.drawable.ic_notification); // Start a lengthy operation in a background thread new Thread( new Runnable() { @Override public void run() { int incr; // Do the "lengthy" operation […]

防止用户解除通知

有些应用程序的通知不能通过将其擦除而解除。 我怎样才能pipe理这样的行为?

如何使用NotificationCompat.Builder创build通知?

我需要创build一个简单的通知,如果可能的话,它会显示在通知栏中,并伴有声音和图标? 我也需要它与Android 2.2兼容,所以我发现NotificationCompat.Builder适用于4以上的所有API。如果有更好的解决scheme,请随时提及它。

蜂窝通知 – 如何将largeIcon设置为正确的大小?

我发现自己好奇为什么Notification.Builder上的setLargeIcon方法只接受一个Bitmap,没有提供资源id的重载。 也许这是出于性能的原因,但它看起来很奇怪,因为setSmallIcon确实接受一个res可绘制的id。 Notification.Builder builder = new Notification.Builder(application); // …. builder.setLargeIcon(iconBitmap); // Requires a Bitmap builder.setSmallIcon(iconResId); // Requires a drawable resource ID Notification notification = builder.getNotification(); 可悲的是提供的位图在通知中没有缩放,所以需要为通知视图提供正确的大小。 假设我需要提供largeIcon位图的xhdpi,hdpi,mdpi和ldpi版本,他们需要什么大小? 我看不到在文档中,或者在search更广泛的网页之后。

如何在android中显示多个通知

我只收到一个通知,如果有另一个通知来,它将取代以前的一个,这里是我的代码 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 […]

更改棒棒糖上的通知图标背景

我正在通过通知devise模式 ,并没有发现任何谈到通知图标背景。 您可能注意到,自定义通知只有浅灰色的背景。 但环聊等应用程序或简单的USBdebugging通知具有自定义的通知图标背景颜色。 有没有可能把灰色变成别的东西? (以编程方式指定特定的圆圈颜色)

自定义通知布局和文字颜色

我的应用程序显示一些通知,并根据用户的喜好,它可能会使用通知中的自定义布局。 它运作良好,但有一个小问题 – 文字颜色 。 股票Android和几乎所有的制造商皮肤使用黑色文本对通知文本的浅色背景,但三星不:他们的通知下拉有一个黑暗的背景,默认通知布局中的文本是白色的。 所以这会导致一个问题:不使用任何花哨布局的通知显示正常,但是使用自定义布局的通知很难阅读,因为文本是黑色的,而不是默认的白色。 即使官方文档只是为TextView设置#000颜色,所以我找不到任何指针。 一个用户很友善地截取了这个问题的截图: 那么如何在我的布局中使用设备的默认通知文字颜色 ? 我宁愿不动手改变基于手机型号的文本颜色,因为这需要大量的更新,而使用自定义ROM的人可能仍然会遇到问题,这取决于他们使用的皮肤。

Android:在线testing推送通知(Google Cloud Messaging)

我正在应用程序中实施Google云消息传递。 由于某些防火墙的限制,服务器代码还没有准备好,而且在我的环境中,我无法部署testing服务器来进行推送通知。 我正在寻找的是一个在线服务器,它会发送一些testing通知到我的设备来testing我的客户端实现。

INSTALL_FAILED_DUPLICATE_PERMISSION … C2D_MESSAGE

我在我的应用程序中使用Google通知,直到现在我已经在清单中完成了以下操作: <!– GCM –> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <!– GCM requires a Google account. –> <uses-permission android:name="android.permission.WAKE_LOCK" /> <!– Keeps the processor from sleeping when a message is received. –> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <!– This app has permission to register and receive data message. –> <!– Creates a custom permission so only this app can receive […]