From 92a6b128a3e5fb8c1cadd29617f6339791668ac9 Mon Sep 17 00:00:00 2001 From: Simon MacDonald Date: Thu, 24 Nov 2016 18:04:25 -0500 Subject: [PATCH] Issue #689: Remove sender id from PushNotification init Android options --- docs/API.md | 4 +--- docs/EXAMPLES.md | 1 - docs/PAYLOAD.md | 6 ++---- docs/TYPESCRIPT.md | 3 +-- src/android/com/adobe/phonegap/push/PushConstants.java | 1 + src/android/com/adobe/phonegap/push/PushPlugin.java | 10 +++++++++- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/docs/API.md b/docs/API.md index e0481af8f..031756d6d 100644 --- a/docs/API.md +++ b/docs/API.md @@ -39,7 +39,6 @@ All available option attributes are described bellow. Currently, there are no Wi Attribute | Type | Default | Description --------- | ---- | ------- | ----------- -`android.senderID` | `string` | | Maps to the project number in the Google Developer Console. `android.icon` | `string` | | Optional. The name of a drawable resource to use as the small-icon. The name should not include the extension. `android.iconColor` | `string` | | Optional. Sets the background color of the small icon on Android 5.0 and greater. [Supported Formats](http://developer.android.com/reference/android/graphics/Color.html#parseColor(java.lang.String)) `android.sound` | `boolean` | `true` | Optional. If `true` it plays the sound specified in the push data or the default system sound. @@ -75,7 +74,7 @@ Attribute | Type | Default | Description --------- | ---- | ------- | ----------- `ios.senderID` | `string` | `undefined` (Native) | Maps to the project number in the Google Developer Console. Setting this uses GCM for notifications instead of native `ios.gcmSandbox` | `boolean` | `false` | Whether to use prod or sandbox GCM setting. Defaults to false. -`ios.topics` | `array` | `[]` | Optional. If the array contains one or more strings each string will be used to subscribe to a GcmPubSub topic. Note: only usable in conjunction with `senderID`. +`ios.topics` | `array` | `[]` | Optional. If the array contains one or more strings each string will be used to subscribe to a GcmPubSub topic. ##### How GCM on iOS works. @@ -99,7 +98,6 @@ Make sure that the certificate you build with matches your `gcmSandbox` value. ```javascript var push = PushNotification.init({ android: { - senderID: "12345679" }, browser: { pushServiceURL: 'http://push.api.phonegap.com/v1/push' diff --git a/docs/EXAMPLES.md b/docs/EXAMPLES.md index 8481e7bcc..32bc2e5fd 100644 --- a/docs/EXAMPLES.md +++ b/docs/EXAMPLES.md @@ -11,7 +11,6 @@ phonegap create my-app --template phonegap-template-push ```javascript var push = PushNotification.init({ android: { - senderID: "12345679" }, browser: { pushServiceURL: 'http://push.api.phonegap.com/v1/push' diff --git a/docs/PAYLOAD.md b/docs/PAYLOAD.md index 7cd307baf..89c0b262b 100644 --- a/docs/PAYLOAD.md +++ b/docs/PAYLOAD.md @@ -129,9 +129,8 @@ By default the icon displayed in your push notification will be your apps icon. ```javascript var push = PushNotification.init({ "android": { - "senderID": "12345679" }, - browser: { + "browser": { pushServiceURL: 'http://push.api.phonegap.com/v1/push' }, "ios": { @@ -154,11 +153,10 @@ In order to get a better user experience you can specify an alternate icon and b ```javascript var push = PushNotification.init({ "android": { - "senderID": "123456789", "icon": "phonegap", "iconColor": "blue" }, - browser: { + "browser": { pushServiceURL: 'http://push.api.phonegap.com/v1/push' }, "ios": { diff --git a/docs/TYPESCRIPT.md b/docs/TYPESCRIPT.md index 37117d168..843a6d913 100644 --- a/docs/TYPESCRIPT.md +++ b/docs/TYPESCRIPT.md @@ -11,7 +11,6 @@ All available attributes and properties will have autocomplete support and type ```typescript let push = PushNotification.init({ android: { - senderID: "12345679" }, ios: { alert: "true", @@ -69,4 +68,4 @@ push.on('notification', (data: my.custom.NotificationEventResponse) => { ## Outdated definitions Is our definition file at DefinitelyTyped outdated? Is there any improvements that could be done? -We welcome any contribution, and they should be done through issues created [there](https://github.com/DefinitelyTyped/DefinitelyTyped/issues/new). \ No newline at end of file +We welcome any contribution, and they should be done through issues created [there](https://github.com/DefinitelyTyped/DefinitelyTyped/issues/new). diff --git a/src/android/com/adobe/phonegap/push/PushConstants.java b/src/android/com/adobe/phonegap/push/PushConstants.java index 6c2394eaf..60784cc25 100644 --- a/src/android/com/adobe/phonegap/push/PushConstants.java +++ b/src/android/com/adobe/phonegap/push/PushConstants.java @@ -69,4 +69,5 @@ public interface PushConstants { public static final String TWILIO_SOUND = "twi_sound"; public static final String START_IN_BACKGROUND = "cdvStartInBackground"; public static final String FORCE_START = "force-start"; + public static final String GOOGLE_APP_ID = "google_app_id"; } diff --git a/src/android/com/adobe/phonegap/push/PushPlugin.java b/src/android/com/adobe/phonegap/push/PushPlugin.java index 67da5edc5..48bd4eeb1 100644 --- a/src/android/com/adobe/phonegap/push/PushPlugin.java +++ b/src/android/com/adobe/phonegap/push/PushPlugin.java @@ -1,5 +1,6 @@ package com.adobe.phonegap.push; +import android.app.Activity; import android.app.NotificationManager; import android.content.Context; import android.content.SharedPreferences; @@ -67,7 +68,7 @@ public void run() { Log.v(LOG_TAG, "execute: jo=" + jo.toString()); - senderID = jo.getString(SENDER_ID); + senderID = getStringResourceByName(GOOGLE_APP_ID); Log.v(LOG_TAG, "execute: senderID=" + senderID); @@ -409,6 +410,13 @@ else if (strValue.startsWith("[")) { return null; } + private String getStringResourceByName(String aString) { + Activity activity = cordova.getActivity(); + String packageName = activity.getPackageName(); + int resId = activity.getResources().getIdentifier(aString, "string", packageName); + return activity.getString(resId); + } + public static boolean isInForeground() { return gForeground; }