38

タイマーが終了したことをユーザーに警告する通知を送信できるようにしたいのですが、通知をクリックしたときに意図したくありません。

インテントに null を渡そうとしました

String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);

int icon = R.drawable.icon;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();

Notification notification = new Notification(icon, tickerText, when);

CharSequence contentTitle = "My notification";
CharSequence contentText = "Hello World!";

notification.setLatestEventInfo(context, contentTitle, contentText, null);
mNotificationManager.notify(HELLO_ID, notification);
4

3 に答える 3

76

パラメータを渡すことができます

PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0)

それ以外の

null

の上

notification.setLatestEventInfo(context, contentTitle, contentText, null);

于 2011-08-12T13:59:41.483 に答える
9

の最後のパラメータsetLatestEventInfo()は ではPendingIntentなくIntentです。タップされたときに何もしない通知が必要な場合は、次のように行われる空の PendingIntent を渡します: PendingIntent.getActivity(context, 0, null, 0)。

于 2011-08-12T14:05:31.840 に答える
1

興味深い質問です。これが機能するかどうかを確認したいと思います。私は少し掘り下げて、同じ質問をしている多くのpplを見つけました. cbursk は、この目的の機能を取得するためのハックを見つけたようです。これは、Activity の代わりに通知インテントに Dialog を渡すことです。ダイアログは何もしないか、すぐに閉じるようにプログラムされていると思いますが、よくわかりません。しかし、私は現在このスレッドを見て、テストするつもりです。

于 2011-08-12T13:44:27.583 に答える