本文介绍了安卓:通知不工作的2.3.6(三星galaxy Y)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面code已被证实做工精细上运行的蜂窝+设备。不过三星银河Ÿ它不产生任何通知。

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.

我不能想办法调试此问题。我不知道如果有什么我失踪。解决这个问题有什么建议是AP preciated。

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没有设置。 姜饼预计,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();

这篇关于安卓:通知不工作的2.3.6(三星galaxy Y)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-19 00:18