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

Commit

Permalink
Issue #750: Show contents of notification when phone is locked
Browse files Browse the repository at this point in the history
  • Loading branch information
macdonst committed Jun 3, 2016
1 parent 3480642 commit ceae864
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
33 changes: 33 additions & 0 deletions docs/PAYLOAD.md
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,39 @@ These phones have a particular quirk that when the app is force closed that you
- On your Xiaomi makes sure your phone has the "Auto-start" property enabled for your app.


## Visibility of Notifications

You can set a visibility parameter for your notifications. Just add a `visibility` field in your notification. -1: secret, 0: private (default), 1: public

```javascript
{
"registration_ids": ["my device id"],
"data": {
"title": "This is a maximum public Notification",
"message": "This notification should appear in front of all others",
"visibility": 1
}
}
```

Here is an example using node-gcm that sends the above JSON:

```javascript
var gcm = require('node-gcm');
// Replace these with your own values.
var apiKey = "replace with API key";
var deviceID = "my device id";
var service = new gcm.Sender(apiKey);
var message = new gcm.Message();
message.addData('title', 'This is a public Notification');
message.addData('message', 'You should be able to read this notification on your lock screen');
message.addData('visibility', 1);
service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) {
if(err) console.error(err);
else console.log(response);
});
```

# iOS Behaviour

## Sound
Expand Down
24 changes: 23 additions & 1 deletion src/android/com/adobe/phonegap/push/GCMIntentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,11 @@ public void createNotification(Context context, Bundle extras) {
*/
setNotificationCount(context, extras, mBuilder);

/*
* Notification count
*/
setVisibility(context, extras, mBuilder);

/*
* Notification add actions
*/
Expand Down Expand Up @@ -408,6 +413,23 @@ private void setNotificationCount(Context context, Bundle extras, NotificationCo
}
}


private void setVisibility(Context context, Bundle extras, NotificationCompat.Builder mBuilder) {
String visibilityStr = extras.getString(VISIBILITY);
if (visibilityStr != null) {
try {
Integer visibility = Integer.parseInt(visibilityStr);
if (visibility >= NotificationCompat.VISIBILITY_SECRET && visibility <= NotificationCompat.VISIBILITY_PUBLIC) {
mBuilder.setVisibility(visibility);
} else {
Log.e(LOG_TAG, "Visibility parameter must be between -1 and 1");
}
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
}

private void setNotificationVibration(Bundle extras, Boolean vibrateOption, NotificationCompat.Builder mBuilder) {
String vibrationPattern = extras.getString(VIBRATION_PATTERN);
if (vibrationPattern != null) {
Expand Down Expand Up @@ -653,7 +675,7 @@ private int parseInt(String value, Bundle extras) {

return retval;
}

private Spanned fromHtml(String source) {
if (source != null)
return Html.fromHtml(source);
Expand Down
1 change: 1 addition & 0 deletions src/android/com/adobe/phonegap/push/PushConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ public interface PushConstants {
public static final String TOPICS = "topics";
public static final String SET_APPLICATION_ICON_BADGE_NUMBER = "setApplicationIconBadgeNumber";
public static final String CLEAR_ALL_NOTIFICATIONS = "clearAllNotifications";
public static final String VISIBILITY = "visibility";
}

0 comments on commit ceae864

Please sign in to comment.