0

当我尝试运行通知时,没有任何弹出

private void pushNotification(String user)
{
    // TODO Auto-generated method stub
    Log.d("Service", "pushNotification");
    Notification notification = new Notification.Builder(this)
    .setContentTitle("Basic Notification ")
    .setContentText("Basic Notification, used earlier").build();
  notification.flags |= Notification.FLAG_AUTO_CANCEL;
  NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
  notificationManager.notify(0, notification);

}
  1. 是因为我没有它的图标吗?
  2. 我需要添加任何东西来推送通知吗?
  3. 另外,我想在单击通知时开始一项活动。我应该怎么办?
4

2 回答 2

0

尝试这样的事情:

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
    .setSmallIcon(R.drawable.ic_launcher)
    .setContentTitle("My notification")
    .setContentText("Hello World!");
    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    Notification noty = mBuilder.build();
    startForeground(mId, noty);

关于单击此文档中的通知时的活动

于 2013-03-07T13:59:53.330 回答
0

尝试这个 :

    private void generateNotification(Context context, String message) {

    int icon = R.drawable.ic_launcher;
    String appname = context.getResources().getString(R.string.app_name);
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Notification notification;
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
            new Intent(context, activity.class), 0);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(
                context);
        notification = builder.setContentIntent(contentIntent)
                .setSmallIcon(icon).setTicker(appname).setWhen(0)
                .setAutoCancel(true).setContentTitle(appname)
                .setContentText(message).build();

        notificationManager.notify(0, notification);
}
于 2013-10-16T09:39:46.357 回答