6

以下に示すように、通知メソッドを作成しました。

NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Notification notification;

        notification = new Notification(R.drawable.messageicon, "You have a new message",
                System.currentTimeMillis());
        notification.flags |= Notification.FLAG_AUTO_CANCEL;

        RemoteViews view = new RemoteViews(getPackageName(), R.layout.notification);
        view.setImageViewResource(R.id.image, R.drawable.ic_launcher);
        view.setTextViewText(R.id.title, "New Message");
        view.setTextViewText(R.id.text, message);
        notification.contentView = view;
        Intent intent = new Intent();
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        PendingIntent activity = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
        notification.contentIntent = activity;
        notificationManager.notify(0, notification);

ステータスバーにボタンを追加したいのですが、ボタンをクリックするとポップアップが表示されます。どんな助けでも大歓迎です。

4

1 に答える 1

11

直接行うことはできませんが、RemoteViews.setOnClickPendingIntent(int viewId, PendingIntent pendingIntent) を使用できます。

すべてのボタンの onClick イベントで同じアクティビティを呼び出す場合は、システムがすべてのボタンに対してすべてのインテントを 1 つだけにマージしないように、別の文字列を使用して Intent.setAction(String action) を追加してください。

次に、アクティビティをダイアログとしてテーマにすると、ポップアップが表示されます。

于 2012-10-22T12:21:33.187 に答える