在android中显示通知

时间:2012-08-04 13:28:39

标签: android android-intent android-emulator android-widget

我使用以下代码在我的Android应用程序中显示通知,但是使用此功能,通知活动也会显示(即黑屏空白)我不想要这个屏幕,但只是一个简单的通知,当用户单击通知然后我想启动活动。应该对此代码做些什么?

        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notify = new Notification(R.drawable.mcube_logo, "Message Sent", Calendar.getInstance().getTimeInMillis());

        Intent intent = new Intent(RecieveAlarm.this, otherActivity.class);
        PendingIntent pendingIntent =PendingIntent.getActivity(RecieveAlarm.this, 1, null, PendingIntent.FLAG_CANCEL_CURRENT);

        notify.setLatestEventInfo(RecieveAlarm.this, "Title", "Details", pendingIntent);
        notificationManager.notify(0, notify);

2 个答案:

答案 0 :(得分:1)

我建议您使用:

        Notification not = new Notification(idIcon, text, System.currentTimeMillis());
    PendingIntent pInt = PendingIntent.getActivity(ctx, 0, new Intent(ctx, the_class_to_call), 0);

    not.setLatestEventInfo(ctx, app_name, text, pInt);

然后not.notify ....

答案 1 :(得分:0)

使用AlertDialog,然后点击正面按钮

启动所需的活动