私はGPSアプリに取り組んでいます。ユーザーが事前定義されたゾーンの内側または外側に移動すると、私のアプリは NotificationManager によって通知を発生させます。私のアプリは、両方のケースで通知を発生させることができます。
onResume() から、クリックされた通知のインテント.setExtra 値ではなく、常に最新のインテント.setExtra() 値を取得します。
問題は、ユーザーがゾーン内またはゾーン外の通知をクリックしたことを検出する方法です。(私は別のケースで別のビューを表示したい)
クリックされた通知のリスナーを追加することは可能ですか?
これが私のコードスピネットです:
private void displayNotificationMessage(String message, boolean vibrate, boolean playSound, Intent contentIntent, String notificationTag)
{
Notification notification = new Notification(R.drawable.buslogo, message, System.currentTimeMillis());
PendingIntent myPendingIntent = PendingIntent.getActivity(this.getBaseContext(),0, contentIntent,PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(this, "Friendly Reminder", message, myPendingIntent);
contentIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
if (vibrate)
notification.vibrate=new long[] {100L, 100L, 200L, 500L};
if (playSound)
notification.defaults |= Notification.DEFAULT_SOUND;
notification.number = ++notificationCounter;
notificationMgr.notify(notificationTag, notificationCounter, notification);
}
@Override
protected void onNewIntent( Intent intent ) {
Log.i( TAG, "*********** onNewIntent(), intent = " + intent );
if (intent.getExtras() != null)
{
Log.i(TAG, "in onNewIntent = " + intent.getExtras().getString("test"));
}
super.onNewIntent( intent );
setIntent( intent );
}
@Override
public void onResume() {
super.onResume();
Log.i(TAG, "*********** Main - onResume()");
Intent intent = this.getIntent();
if (intent.getExtras() != null)
{
Log.i(TAG, "test = " + intent.getExtras().getString("test"));
}
}
public void createNotification(String msnContent)
{
Intent intent = new Intent();
intent.setClass(this, Main.class);
Bundle bundle = new Bundle();
bundle.putString("test", msnContent);
intent.putExtras(bundle);
displayNotificationMessage(msnContent, true, true, intent, "test");
}