3

NotificationCompat を使用して、他の質問のおかげで通知を正常に作成しました。通知がonClickで行うことを変更したいだけです。アラート ダイアログがポップアップ表示されるようにしたいのですが (いくつかのアプリでそれが行われているのを見てきました)、クリックするたびに自分のアクティビティが表示されます。何か案は?

通知コード:

Intent notificationIntent = new Intent(ctx, YourClass.class);
PendingIntent contentIntent = PendingIntent.getActivity(ctx,
        YOUR_PI_REQ_CODE, notificationIntent,
        PendingIntent.FLAG_CANCEL_CURRENT);

NotificationManager nm = (NotificationManager) ctx
        .getSystemService(Context.NOTIFICATION_SERVICE);

Resources res = ctx.getResources();
Notification.Builder builder = new Notification.Builder(ctx);

builder.setContentIntent(contentIntent)
            .setSmallIcon(R.drawable.some_img)
            .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.some_big_img))
            .setTicker(res.getString(R.string.your_ticker))
            .setWhen(System.currentTimeMillis())
            .setAutoCancel(true)
            .setContentTitle(res.getString(R.string.your_notif_title))
            .setContentText(res.getString(R.string.your_notif_text));
Notification n = builder.build();

nm.notify(YOUR_NOTIF_ID, n);
4

3 に答える 3

2

アクティビティがなければ、通常のダイアログはありません。ダイアログのようにアクティビティをスタイリングし、アクティビティ自体を非表示にし、そこからダイアログをすぐに起動するなど、いくつかの回避策が考えられます。

于 2012-10-12T00:40:08.970 に答える
0

アプリ プロセスに移動せずに、リモート ビューを使用してダイアログを表示できる可能性があります。

于 2012-10-12T00:45:36.627 に答える