gecko-dev/mobile/android/base/NotificationHandler.java.in
Brian Nicholson fe44f36220 Bug 850487 - More code cleanup (@Overrides and unused imports). r=kats
--HG--
extra : rebase_source : 376574e0c41b91c16a6be335584a4a61768bb4a9
2013-03-13 13:20:57 -07:00

67 lines
2.3 KiB
Java

/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#filter substitution
package @ANDROID_PACKAGE_NAME@;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
public class NotificationHandler extends BroadcastReceiver {
private static final String LOGTAG = "GeckoNotificationHandler";
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null)
handleIntent(context, intent);
}
protected void handleIntent(Context context, Intent notificationIntent) {
// only fire the callback if the intent was clicked, not if it was cancelled
String action = notificationIntent.getAction();
if (App.ACTION_ALERT_CLEAR.equals(action))
return;
String appName = "";
Uri data = notificationIntent.getData();
if (data != null) {
appName = data.getQueryParameter("app");
if (appName == null)
appName = "@ANDROID_PACKAGE_NAME@.App";
}
sendIntent(context, App.ACTION_ALERT_CALLBACK,
appName,
data);
}
private void sendIntent(Context context, String action, String className, Uri data) {
Intent appIntent = new Intent(action);
if (TextUtils.isEmpty(className))
appIntent.setClassName(context, "@ANDROID_PACKAGE_NAME@.App");
else
appIntent.setClassName(context, className);
appIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (data != null)
appIntent.setData(data);
try {
Log.i(LOGTAG, "startActivity with intent: Action='" + appIntent.getAction() +
" appName='" + className + "'");
context.startActivity(appIntent);
} catch (ActivityNotFoundException e) {
Log.e(LOGTAG, "NotificationHandler Exception: ", e);
}
}
}