This repository has been archived by the owner on Sep 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #551: Handling notifications in the background (without loading…
… the app UI)
- Loading branch information
Showing
5 changed files
with
72 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/android/com/adobe/phonegap/push/BackgroundActionButtonHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.adobe.phonegap.push; | ||
|
||
import android.app.NotificationManager; | ||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
|
||
public class BackgroundActionButtonHandler extends BroadcastReceiver implements PushConstants { | ||
private static String LOG_TAG = "PushPlugin_BackgroundActionButtonHandler"; | ||
|
||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
Bundle extras = intent.getExtras(); | ||
Log.d(LOG_TAG, "BackgroundActionButtonHandler = " + extras); | ||
|
||
int notId = intent.getIntExtra(NOT_ID, 0); | ||
Log.d(LOG_TAG, "not id = " + notId); | ||
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); | ||
notificationManager.cancel(GCMIntentService.getAppName(context), notId); | ||
|
||
if (extras != null) { | ||
Bundle originalExtras = extras.getBundle(PUSH_BUNDLE); | ||
|
||
originalExtras.putBoolean(FOREGROUND, false); | ||
originalExtras.putBoolean(COLDSTART, false); | ||
originalExtras.putString(CALLBACK, extras.getString("callback")); | ||
PushPlugin.sendExtras(originalExtras); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -337,10 +337,22 @@ private void createActions(Bundle extras, NotificationCompat.Builder mBuilder, R | |
Log.d(LOG_TAG, "adding action"); | ||
JSONObject action = actionsArray.getJSONObject(i); | ||
Log.d(LOG_TAG, "adding callback = " + action.getString(CALLBACK)); | ||
Intent intent = new Intent(this, PushHandlerActivity.class); | ||
intent.putExtra(CALLBACK, action.getString(CALLBACK)); | ||
intent.putExtra(PUSH_BUNDLE, extras); | ||
PendingIntent pIntent = PendingIntent.getActivity(this, i, intent, PendingIntent.FLAG_UPDATE_CURRENT); | ||
boolean foreground = action.getBoolean(FOREGROUND); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
fredgalvao
Collaborator
|
||
Intent intent = null; | ||
PendingIntent pIntent = null; | ||
if (foreground) { | ||
intent = new Intent(this, PushHandlerActivity.class); | ||
intent.putExtra(CALLBACK, action.getString(CALLBACK)); | ||
intent.putExtra(PUSH_BUNDLE, extras); | ||
intent.putExtra(FOREGROUND, foreground); | ||
pIntent = PendingIntent.getActivity(this, i, intent, PendingIntent.FLAG_UPDATE_CURRENT); | ||
} else { | ||
intent = new Intent(this, BackgroundActionButtonHandler.class); | ||
intent.putExtra(CALLBACK, action.getString(CALLBACK)); | ||
intent.putExtra(PUSH_BUNDLE, extras); | ||
intent.putExtra(FOREGROUND, foreground); | ||
pIntent = PendingIntent.getBroadcast(this, i, intent, PendingIntent.FLAG_UPDATE_CURRENT); | ||
} | ||
|
||
mBuilder.addAction(resources.getIdentifier(action.getString(ICON), DRAWABLE, packageName), | ||
action.getString(TITLE), pIntent); | ||
|
@@ -586,7 +598,7 @@ public Bitmap getBitmapFromURL(String strURL) { | |
} | ||
} | ||
|
||
private static String getAppName(Context context) { | ||
public static String getAppName(Context context) { | ||
CharSequence appName = context.getPackageManager().getApplicationLabel(context.getApplicationInfo()); | ||
return (String)appName; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@macdonst If
foreground
is absent from the JSON object, it'll run as if the deafult value for it wasfalse
, won't it? If so, it goes against the documented default value oftrue
.