Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
…push into hanicker-master

Conflicts:
	docs/PAYLOAD.md
	src/android/com/adobe/phonegap/push/PushConstants.java
  • Loading branch information
macdonst committed Nov 1, 2016
2 parents b639d83 + 8c03bef commit 4340290
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 4 deletions.
25 changes: 25 additions & 0 deletions docs/INSTALLATION.md
Expand Up @@ -89,6 +89,31 @@ For more detailed instructions on how to install the Android Support Library vis
android update sdk --no-ui --filter "extra"
```

### Notification after forced closing

To use payload parameter "force-start" this code must be added in MainActivity.java:

```
boolean startOnBackground = false;
Bundle extras = getIntent().getExtras();
if (extras != null) {
startOnBackground = extras.getBoolean(PushConstants.START_ON_BACKGROUND);
if(startOnBackground) {
moveTaskToBack(true);
}
}
// Set by <content src="index.html" /> in config.xml
loadUrl(launchUrl);
super.loadUrl("javascript: { window.startOnBackground = "+(startOnBackground?1:0)+"; }");
```

right after

```
super.onCreate(savedInstanceState);
```

### Co-existing with Facebook Plugin

There are a number of Cordova Facebook Plugins available but the one that we recommend is [Jeduan's fork](https://github.com/jeduan/cordova-plugin-facebook4) of the original Wizcorp plugin. It is setup to use Gradle/Maven and the latest Facebook SDK properly.
Expand Down
4 changes: 4 additions & 0 deletions docs/PAYLOAD.md
Expand Up @@ -17,6 +17,7 @@
- [Background Notifications](#background-notifications)
- [Use of content-available: true](#use-of-content-available-true)
- [Huawei and Xiaomi Phones](#huawei-and-xiaomi-phones)
- [Application force closed](#application-force-closed)
- [Visibility](#visibility-of-notifications)
- [Badges](#badges)
- [Support for Twilio Notify](#support-for-twilio-notify)
Expand Down Expand Up @@ -946,6 +947,9 @@ These phones have a particular quirk that when the app is force closed that you
- On your Huawei device go to Settings > Protected apps > check "My App" where.
- On your Xiaomi makes sure your phone has the "Auto-start" property enabled for your app.

### Application force closed

It is possible to add `force-start: true` to the data payload to restart application in background even if force closed.

## Visibility of Notifications

Expand Down
9 changes: 9 additions & 0 deletions src/android/com/adobe/phonegap/push/GCMIntentService.java
Expand Up @@ -277,6 +277,7 @@ private void showNotificationIfPossible (Context context, Bundle extras) {
String message = extras.getString(MESSAGE);
String title = extras.getString(TITLE);
String contentAvailable = extras.getString(CONTENT_AVAILABLE);
String forceStart = "1"; //extras.getString(FORCE_START);
int badgeCount = extractBadgeCount(extras);
if (badgeCount >= 0) {
Log.d(LOG_TAG, "count =[" + badgeCount + "]");
Expand All @@ -303,6 +304,14 @@ private void showNotificationIfPossible (Context context, Bundle extras) {
Log.d(LOG_TAG, "send notification event");
PushPlugin.sendExtras(extras);
}

if(!PushPlugin.isActive() && "1".equals(forceStart)){
Intent intent = new Intent(this, PushHandlerActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(PUSH_BUNDLE, extras);
intent.putExtra(START_ON_BACKGROUND, true);
startActivity(intent);
}
}

public void createNotification(Context context, Bundle extras) {
Expand Down
2 changes: 2 additions & 0 deletions src/android/com/adobe/phonegap/push/PushConstants.java
Expand Up @@ -67,4 +67,6 @@ public interface PushConstants {
public static final String TWILIO_BODY = "twi_body";
public static final String TWILIO_TITLE = "twi_title";
public static final String TWILIO_SOUND = "twi_sound";
public static final String START_ON_BACKGROUND = "start-on-background";
public static final String FORCE_START = "force-start";
}
26 changes: 22 additions & 4 deletions src/android/com/adobe/phonegap/push/PushHandlerActivity.java
Expand Up @@ -28,13 +28,17 @@ public void onCreate(Bundle savedInstanceState) {
int notId = intent.getExtras().getInt(NOT_ID, 0);
Log.d(LOG_TAG, "not id = " + notId);
gcm.setNotification(notId, "");
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(GCMIntentService.getAppName(this), notId);
super.onCreate(savedInstanceState);
Log.v(LOG_TAG, "onCreate");
String callback = getIntent().getExtras().getString("callback");
Log.d(LOG_TAG, "callback = " + callback);
boolean foreground = getIntent().getExtras().getBoolean("foreground", true);
boolean startOnBackground = getIntent().getExtras().getBoolean(START_ON_BACKGROUND, true);

if(!startOnBackground){
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(GCMIntentService.getAppName(this), notId);
}

Log.d(LOG_TAG, "bringToForeground = " + foreground);

Expand All @@ -47,7 +51,9 @@ public void onCreate(Bundle savedInstanceState) {

if (!isPushPluginActive && foreground && inline) {
Log.d(LOG_TAG, "forceMainActivityReload");
forceMainActivityReload();
forceMainActivityReload(false);
} else if(startOnBackground) {
forceMainActivityReload(true);
} else {
Log.d(LOG_TAG, "don't want main activity");
}
Expand Down Expand Up @@ -83,9 +89,21 @@ private boolean processPushBundle(boolean isPushPluginActive, Intent intent) {
/**
* Forces the main activity to re-launch if it's unloaded.
*/
private void forceMainActivityReload() {
private void forceMainActivityReload(boolean startOnBackground) {
PackageManager pm = getPackageManager();
Intent launchIntent = pm.getLaunchIntentForPackage(getApplicationContext().getPackageName());

Bundle extras = getIntent().getExtras();
if (extras != null) {
Bundle originalExtras = extras.getBundle(PUSH_BUNDLE);
if (originalExtras != null) {
launchIntent.putExtras(originalExtras);
}
launchIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
launchIntent.addFlags(Intent.FLAG_FROM_BACKGROUND);
launchIntent.putExtra(START_ON_BACKGROUND, true);
}

startActivity(launchIntent);
}

Expand Down

0 comments on commit 4340290

Please sign in to comment.