Bug 608624 - Clearing update notification launches fennec r=blassey a=dougt

This commit is contained in:
Alex Pakhotin 2010-11-30 21:57:21 -08:00
parent b83cb30807
commit 656785cddf
3 changed files with 14 additions and 22 deletions

View File

@ -64,14 +64,12 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name="NotificationHandler" <receiver android:name="NotificationHandler">
android:label="@MOZ_APP_DISPLAYNAME@ Notification"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter> <intent-filter>
<action android:name="org.mozilla.gecko.ACTION_ALERT_CLICK" /> <action android:name="org.mozilla.gecko.ACTION_ALERT_CLICK" />
<action android:name="org.mozilla.gecko.ACTION_ALERT_CLEAR" /> <action android:name="org.mozilla.gecko.ACTION_ALERT_CLEAR" />
</intent-filter> </intent-filter>
</activity> </receiver>
<activity android:name="Restarter" <activity android:name="Restarter"
android:theme="@android:style/Theme.Light.NoTitleBar"> android:theme="@android:style/Theme.Light.NoTitleBar">

View File

@ -528,7 +528,7 @@ class GeckoAppShell
Uri dataUri = Uri.fromParts("alert", aAlertName, aAlertCookie); Uri dataUri = Uri.fromParts("alert", aAlertName, aAlertCookie);
notificationIntent.setData(dataUri); 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); 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 // 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, clearNotificationIntent.setClassName(GeckoApp.mAppContext,
"org.mozilla." + GeckoApp.mAppContext.getAppName() + ".NotificationHandler"); "org.mozilla." + GeckoApp.mAppContext.getAppName() + ".NotificationHandler");
clearNotificationIntent.setData(dataUri); clearNotificationIntent.setData(dataUri);
notification.deleteIntent = PendingIntent.getBroadcast(GeckoApp.mAppContext, 0, clearNotificationIntent, 0);
PendingIntent pendingClearIntent = PendingIntent.getActivity(GeckoApp.mAppContext, 0, clearNotificationIntent, 0);
notification.deleteIntent = pendingClearIntent;
mAlertNotifications.put(notificationID, notification); mAlertNotifications.put(notificationID, notification);

View File

@ -38,30 +38,25 @@
#filter substitution #filter substitution
package org.mozilla.@MOZ_APP_NAME@; package org.mozilla.@MOZ_APP_NAME@;
import android.app.Activity;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.content.Intent; import android.content.Intent;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.net.Uri; import android.net.Uri;
public class NotificationHandler public class NotificationHandler
extends Activity extends BroadcastReceiver
{ {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { public void onReceive(Context context, Intent intent) {
super.onCreate(savedInstanceState);
Log.i("GeckoAppJava", "NotificationHandler.onCreate");
Intent intent = getIntent();
if (intent != null) if (intent != null)
handleIntent(intent); handleIntent(context, intent);
finish();
} }
protected void handleIntent(Intent notificationIntent) { protected void handleIntent(Context context, Intent notificationIntent) {
String action = notificationIntent.getAction(); String action = notificationIntent.getAction();
String alertName = ""; String alertName = "";
String alertCookie = ""; String alertCookie = "";
@ -87,16 +82,17 @@ public class NotificationHandler
App.mAppContext.handleNotification(action, alertName, alertCookie); App.mAppContext.handleNotification(action, alertName, alertCookie);
} else { } else {
// The app is not running, just cancel this notification // 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); notificationManager.cancel(notificationID);
} }
if (App.ACTION_ALERT_CLICK.equals(action)) { if (App.ACTION_ALERT_CLICK.equals(action)) {
// Start or bring to front the main activity // Start or bring to front the main activity
Intent appIntent = new Intent(Intent.ACTION_MAIN); 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 { try {
startActivity(appIntent); context.startActivity(appIntent);
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
Log.e("GeckoAppJava", "NotificationHandler Exception: " + e.getMessage()); Log.e("GeckoAppJava", "NotificationHandler Exception: " + e.getMessage());
} }