我正在尝试提醒用户收到了一条消息。我已经添加了一个操作,期望在通知上显示一个小红球图标。如果用户点击小红球,主活动将启动并检查额外的包,看到要执行与正常启动不同的操作指令。
通知会显示在目标手机(运行KitKat)上,同时显示文本,但小红球图标从未显示。当用户触摸通知时,活动会执行但没有额外的内容。编辑:现在活动正在获取额外的包。
这是发送通知的代码:
通知会显示在目标手机(运行KitKat)上,同时显示文本,但小红球图标从未显示。当用户触摸通知时,活动会执行但没有额外的内容。编辑:现在活动正在获取额外的包。
这是发送通知的代码:
private void raiseNotification( String username, String mesText)
{
DebugLog.debugLog("GCMIntentService: Attempting to Raise Notification ", false);
NotificationCompat.Builder b = new NotificationCompat.Builder(this);
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("whattodo", "showmessage");
intent.setAction(Long.toString(System.currentTimeMillis())); //just to make it unique from the next one
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
b.setContentTitle("New SafeTalk Message")
.setSmallIcon(R.drawable.note24x24)
.setContentText("From " + username + " " + mesText)
.setTicker("New SafeTalk Message")
.setContentIntent(pIntent)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setAutoCancel(true)
.addAction(R.drawable.smallredball, "Read Now", pIntent);
NotificationManager mgr = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
mgr.notify(0, b.build());
}
这是来自活动的代码片段:
Bundle extras = getIntent().getExtras();
if (extras == null)
{
GlobalStuff.mpBad.start();
}
else
{
String myOrders = extras.getString("whattodo");
if (myOrders.equals("showmessage"))
GlobalStuff.mpBeep.start();
}
为什么通知中的图标没有显示?我已将 setAutoCancel 设置为 true,希望只需轻触通知即可使其消失。但实际上它会启动应用程序,而不提供任何额外的信息包。
谢谢, 迪恩