Android:通知不适用于 2.3.6(三星 Galaxy y) [英] Android : Notification not working on 2.3.6 (Samsung galaxy y)

查看:15
本文介绍了Android:通知不适用于 2.3.6(三星 Galaxy y)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已确认以下代码在运行 HONEYCOMB+ 的设备上可以正常工作.然而,在三星 Galaxy Y 上,它不会产生任何通知.

The following code has been confirmed to work fine on devices running HONEYCOMB+. However on Samsung galaxy Y it is not producing any notifications.

        String tickerText = userString + " Download Queued";
        Notification notification =  new NotificationCompat.Builder(this).setAutoCancel(true)
                                                .setContentTitle(userString)
                                                .setContentText("Queued")
                                                .setSmallIcon(R.drawable.stat_sys_download_done)
                                                .setWhen(System.currentTimeMillis())
                                                .setTicker(tickerText)
                                                .build();
        if(DBG_ENABLE) {
            LogUtils.logD(TAG_LOG, "Posting queue notification : " + 0);
        }
        NotificationManager notificationManager =
                (NotificationManager) getApplicationContext().getSystemService(NOTIFICATION_SERVICE);
        notificationManager.notify(0, notification);

注意:

  • 我在日志中看到了发布队列通知".
  • 我已将可绘制的 stat_sys_download_done 从 android sdk 复制到我的项目中.
  • I see the "Posting Queue notification" in the logs.
  • I have copied the drawable stat_sys_download_done from android sdk into my project.

我想不出调试这个问题的方法.我不确定是否有任何我遗漏的东西.任何解决此问题的建议表示赞赏.

I'm not able to think of a way to debug this problem. I'm not sure if there is anything I'm missing. Any suggestions to fix this is appreciated.

推荐答案

正如 CommonsWare 所建议的,我在 2.3 模拟器上运行该应用程序,但它崩溃了.未设置 ContentIntent 的原因.GingerBread 需要 ContentIntent.所以我添加了一个虚拟的待处理意图,如:

As CommonsWare suggested, I ran the app on a 2.3 emulator and it crashed. Reason being ContentIntent was not set. GingerBread expects a ContentIntent. So I added a dummy pending intent like :

            PendingIntent pi = PendingIntent.getBroadcast(this, 0, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT);
            Notification notification =  new NotificationCompat.Builder(this).setAutoCancel(true)
                                            .setContentTitle(userString)
                                            .setContentText("Queued")
                                            .setContentIntent(pi)
                                            .setSmallIcon(R.drawable.stat_sys_download_done)
                                            .setWhen(System.currentTimeMillis())
                                            .setTicker(tickerText)
                                            .build();

这篇关于Android:通知不适用于 2.3.6(三星 Galaxy y)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆