From 059754636961405450fa59b07e9a790d7b40fdff Mon Sep 17 00:00:00 2001 From: Alex Pakhotin Date: Tue, 30 Nov 2010 21:57:21 -0800 Subject: [PATCH] Bug 608624 - Clearing update notification launches fennec r=blassey a=dougt --- embedding/android/AndroidManifest.xml.in | 6 ++--- embedding/android/GeckoAppShell.java | 6 ++--- embedding/android/NotificationHandler.java.in | 24 ++++++++----------- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/embedding/android/AndroidManifest.xml.in b/embedding/android/AndroidManifest.xml.in index 17d0f732330b..37eb45738e26 100644 --- a/embedding/android/AndroidManifest.xml.in +++ b/embedding/android/AndroidManifest.xml.in @@ -64,14 +64,12 @@ - + - + diff --git a/embedding/android/GeckoAppShell.java b/embedding/android/GeckoAppShell.java index acad1715e4af..5604a28309e0 100644 --- a/embedding/android/GeckoAppShell.java +++ b/embedding/android/GeckoAppShell.java @@ -528,7 +528,7 @@ class GeckoAppShell Uri dataUri = Uri.fromParts("alert", aAlertName, aAlertCookie); notificationIntent.setData(dataUri); - PendingIntent contentIntent = PendingIntent.getActivity(GeckoApp.mAppContext, 0, notificationIntent, 0); + PendingIntent contentIntent = PendingIntent.getBroadcast(GeckoApp.mAppContext, 0, notificationIntent, 0); notification.setLatestEventInfo(GeckoApp.mAppContext, aAlertTitle, aAlertText, contentIntent); // The intent to execute when the status entry is deleted by the user with the "Clear All Notifications" button @@ -536,9 +536,7 @@ class GeckoAppShell clearNotificationIntent.setClassName(GeckoApp.mAppContext, "org.mozilla." + GeckoApp.mAppContext.getAppName() + ".NotificationHandler"); clearNotificationIntent.setData(dataUri); - - PendingIntent pendingClearIntent = PendingIntent.getActivity(GeckoApp.mAppContext, 0, clearNotificationIntent, 0); - notification.deleteIntent = pendingClearIntent; + notification.deleteIntent = PendingIntent.getBroadcast(GeckoApp.mAppContext, 0, clearNotificationIntent, 0); mAlertNotifications.put(notificationID, notification); diff --git a/embedding/android/NotificationHandler.java.in b/embedding/android/NotificationHandler.java.in index 1e109e413476..787222931fe4 100644 --- a/embedding/android/NotificationHandler.java.in +++ b/embedding/android/NotificationHandler.java.in @@ -38,30 +38,25 @@ #filter substitution package org.mozilla.@MOZ_APP_NAME@; -import android.app.Activity; import android.app.NotificationManager; import android.content.Intent; import android.content.ActivityNotFoundException; +import android.content.BroadcastReceiver; +import android.content.Context; import android.os.Bundle; import android.util.Log; import android.net.Uri; public class NotificationHandler - extends Activity + extends BroadcastReceiver { @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - Log.i("GeckoAppJava", "NotificationHandler.onCreate"); - - Intent intent = getIntent(); + public void onReceive(Context context, Intent intent) { if (intent != null) - handleIntent(intent); - - finish(); + handleIntent(context, intent); } - protected void handleIntent(Intent notificationIntent) { + protected void handleIntent(Context context, Intent notificationIntent) { String action = notificationIntent.getAction(); String alertName = ""; String alertCookie = ""; @@ -87,16 +82,17 @@ public class NotificationHandler App.mAppContext.handleNotification(action, alertName, alertCookie); } else { // The app is not running, just cancel this notification - NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(notificationID); } if (App.ACTION_ALERT_CLICK.equals(action)) { // Start or bring to front the main activity Intent appIntent = new Intent(Intent.ACTION_MAIN); - appIntent.setClassName(this, "org.mozilla.@MOZ_APP_NAME@.App"); + appIntent.setClassName(context, "org.mozilla.@MOZ_APP_NAME@.App"); + appIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { - startActivity(appIntent); + context.startActivity(appIntent); } catch (ActivityNotFoundException e) { Log.e("GeckoAppJava", "NotificationHandler Exception: " + e.getMessage()); }