我一整天都在尝试从 ASyncTask 获取成功上传的通知。我当前的代码没有收到任何错误,但无法在通知栏(或其他任何地方)中显示通知。我在 LogCat 中没有收到任何消息,并且通知栏中没有显示任何通知。这是我的代码:
Notification mNotification = new Notification(icon, tickerText, when);
CharSequence contentTitle = "upload completed.";
CharSequence contentText = "upload completed.";
Intent notificationIntent = new Intent(context, CastrActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_NO_CREATE);
mNotification.contentIntent = contentIntent;
mNotification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mNotification);
这是从 ASyncTask 的 onPostExecute() 方法调用的。老实说,我对 PendingIntent 部分有点困惑。任何对我怀疑的不正确代码的澄清将不胜感激。
即使您的问题已解决,我也会发布如何解决通知未显示的问题,也许它可能会帮助其他人阅读答案:
在我的通知大楼中,我缺少该图标。一旦我添加了类似的东西setSmallIcon(R.drawable.ic_launcher)
显示了通知。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)