Skip to content

Commit 8fb7130

Browse files
committed
Merge remote-tracking branch 'upstream/master'
# Conflicts: # src/android/ParsePushPluginReceiver.java
2 parents c22d69f + 67124cf commit 8fb7130

36 files changed

Lines changed: 875 additions & 596 deletions

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,13 @@ The comments contain all the explanations and hints you will need. Mimic the cod
311311
</resources>
312312
```
313313

314+
You can provide a property `ParseNotificationIcon` in `config.xml` to provide a custom android notification icon for Android Lollipop and above like this:
315+
316+
```xml
317+
<preference name="ParseNotificationIcon" value="android_notification_icon" />
318+
```
319+
320+
The icon has to be in folder `resources` in project root and with extension `.png`. The icon is then copied to `platforms/android/res/drawable/<PROVIDED-NAME>.png`. For details, how to design the icon have a look at https://clevertap.com/blog/fixing-notification-icon-for-android-lollipop-and-above/
314321

315322
#### iOS:
316323

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "parse-push-plugin",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"description": "Parse.Push plugin for phonegap/cordova/ionic",
55
"cordova": {
66
"id": "parse-push-plugin",

plugin.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<plugin xmlns="http://www.apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="parse-push-plugin" version="1.0.7">
3+
<plugin xmlns="http://www.apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="parse-push-plugin" version="1.0.8">
44
<name>ParsePushPlugin</name>
55
<description>Parse.Push plugin for phonegap/cordova/ionic framework</description>
66
<keywords>cordova,phonegap,ionic framework, parse server, parse push, push notification</keywords>
@@ -43,9 +43,9 @@
4343
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
4444
</config-file>
4545

46-
<framework src="com.parse:parse-android:1.13.0" />
47-
<framework src="com.parse.bolts:bolts-android:1.4.0" />
46+
<framework src="com.parse:parse-android:1.16.7" />
4847
<framework src="com.android.support:support-v4:+" />
48+
<framework src="me.leolin:ShortcutBadger:1.1.17@aar" />
4949

5050
<source-file src="src/android/ParsePushPlugin.java" target-dir="src/github/taivo/parsepushplugin" />
5151
<source-file src="src/android/ParsePushPluginReceiver.java" target-dir="src/github/taivo/parsepushplugin" />

scripts/afterAndroidPrepare.js

Lines changed: 54 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,67 @@
1-
module.exports = function(context) {
2-
//
3-
// Copy gcm sender id from config.xml into AndroidManifest
4-
//
1+
module.exports = function (context) {
2+
var fs = context.requireCordovaModule('fs');
3+
var path = context.requireCordovaModule('path');
4+
var ET = context.requireCordovaModule('elementtree');
5+
var ConfigFile = context.requireCordovaModule("cordova-common").ConfigFile;
56

6-
var path = context.requireCordovaModule('path');
7-
var ET = context.requireCordovaModule('elementtree');
8-
var ConfigFile = context.requireCordovaModule("cordova-common").ConfigFile;
7+
var configXml = new ConfigFile(context.opts.projectRoot, null, './config.xml');
98

10-
var configXml = new ConfigFile(context.opts.projectRoot, null, './config.xml');
9+
// find the meta-data node in AndroidManifest.xml
10+
var androidPrjDir = path.join(context.opts.projectRoot, 'platforms/android');
11+
var androidManifest = new ConfigFile(androidPrjDir, 'android', 'AndroidManifest.xml');
12+
var applicationNode = androidManifest.data.find('application');
1113

12-
//
13-
// detect parse.com or parse-server mode
14-
var parseServerUrl = configXml.data.find('preference[@name="ParseServerUrl"]').get('value');
14+
// detect Parse notification icon
15+
var parsePushNotificationIcon = configXml.data.find('preference[@name="ParseNotificationIcon"]').get('value');
16+
if (!!parsePushNotificationIcon) {
17+
// add to AndroidManifest.xml
18+
var manifestPushNotificationIconNode = applicationNode.find('meta-data[@android:name="com.parse.push.notification_icon"]');
1519

16-
if(parseServerUrl.toUpperCase() !== "PARSE_DOT_COM"){
17-
//
18-
//opensource parse-server requires own GcmSenderId, so copy it from config.xml to AndroidManifest
19-
//
20-
var configXmlGcmIdNode = configXml.data.find('preference[@name="ParseGcmSenderId"]');
21-
if(!configXmlGcmIdNode){
22-
console.error("ParseGcmSenderId is not set in config.xml");
23-
return false;
24-
}
20+
if (!manifestPushNotificationIconNode) {
21+
manifestPushNotificationIconNode = new ET.Element('meta-data', { 'android:name': 'com.parse.push.notification_icon' });
22+
applicationNode.append(manifestPushNotificationIconNode);
23+
}
24+
manifestPushNotificationIconNode.set('android:resource', '@drawable/' + parsePushNotificationIcon);
2525

26-
//
27-
// find the meta-data node in AndroidManifest.xml to copy the sender id into
28-
//
29-
var androidPrjDir = path.join(context.opts.projectRoot, 'platforms/android');
30-
var androidManifest = new ConfigFile(androidPrjDir, 'android', 'AndroidManifest.xml');
26+
// COPY ICON
27+
// create target path
28+
var iconTargetPath = path.join(context.opts.projectRoot, 'platforms', 'android', 'res', 'drawable');
29+
try {
30+
fs.mkdirSync(iconTargetPath);
31+
} catch (err) {
32+
// Directory already exists
33+
}
3134

32-
var applicationNode = androidManifest.data.find('application');
33-
var manifestGcmIdNode = applicationNode.find('meta-data[@android:name="com.parse.push.gcm_sender_id"]');
35+
// copy icon to android folder
36+
fs
37+
.createReadStream(path.join(context.opts.projectRoot, 'resources', parsePushNotificationIcon + '.png'))
38+
.pipe(fs.createWriteStream(path.join(iconTargetPath, parsePushNotificationIcon + '.png')));
39+
}
3440

35-
if(!manifestGcmIdNode){
36-
manifestGcmIdNode = new ET.Element('meta-data', {'android:name': 'com.parse.push.gcm_sender_id'});
37-
applicationNode.append( manifestGcmIdNode );
38-
}
41+
// Copy gcm sender id from config.xml into AndroidManifest
42+
// detect parse.com or parse-server mode
43+
var parseServerUrl = configXml.data.find('preference[@name="ParseServerUrl"]').get('value');
3944

40-
manifestGcmIdNode.set('android:value', 'id:' + configXmlGcmIdNode.get('value'));
41-
androidManifest.save();
42-
}
45+
if (parseServerUrl.toUpperCase() !== "PARSE_DOT_COM") {
46+
//opensource parse-server requires own GcmSenderId, so copy it from config.xml to AndroidManifest
47+
var configXmlGcmIdNode = configXml.data.find('preference[@name="ParseGcmSenderId"]');
48+
if (!configXmlGcmIdNode) {
49+
console.error("ParseGcmSenderId is not set in config.xml");
50+
return false;
51+
}
4352

53+
var manifestGcmIdNode = applicationNode.find('meta-data[@android:name="com.parse.push.gcm_sender_id"]');
4454

55+
if (!manifestGcmIdNode) {
56+
manifestGcmIdNode = new ET.Element('meta-data', { 'android:name': 'com.parse.push.gcm_sender_id' });
57+
applicationNode.append(manifestGcmIdNode);
58+
}
4559

60+
manifestGcmIdNode.set('android:value', 'id:' + configXmlGcmIdNode.get('value'));
61+
}
4662

47-
return true;
63+
64+
androidManifest.save();
65+
66+
return true;
4867
}

src/android/ParsePushApplication.java

Lines changed: 57 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -28,71 +28,67 @@
2828
i.e., android:name="com.custom.package.MainApplication"
2929
*/
3030
public class ParsePushApplication extends Application {
31-
public static final String LOGTAG = "ParsePushApplication";
31+
public static final String LOGTAG = "ParsePushApplication";
3232

33-
@Override
34-
public void onCreate(){
35-
super.onCreate();
33+
@Override
34+
public void onCreate() {
35+
super.onCreate();
3636

37-
try {
38-
// Other ways to call ParsePushReaderConfig:
39-
//
40-
// - Tell the reader to parse custom parameters, e.g., <preference name="CustomParam1" value="foo" />
41-
// ParsePushConfigReader config = new ParsePushConfigReader(getApplicationContext(), null, new String[] {"CustomParam1", "CustomParam2"});
42-
//
43-
// - If you write your own MainApplication in your app package, just import com.yourpackage.R and skip detecting R.xml.config
44-
// ParsePushConfigReader config = new ParsePushConfigReader(getApplicationContext(), R.xml.config, null);
45-
//
37+
try {
38+
// Other ways to call ParsePushReaderConfig:
39+
//
40+
// - Tell the reader to parse custom parameters, e.g., <preference name="CustomParam1" value="foo" />
41+
// ParsePushConfigReader config = new ParsePushConfigReader(getApplicationContext(), null, new String[] {"CustomParam1", "CustomParam2"});
42+
//
43+
// - If you write your own MainApplication in your app package, just import com.yourpackage.R and skip detecting R.xml.config
44+
// ParsePushConfigReader config = new ParsePushConfigReader(getApplicationContext(), R.xml.config, null);
45+
//
4646

47+
// Simple config reading for opensource parse-server:
48+
// 1st null to detect R.xml.config resource id, 2nd null indicates no custom config param
49+
//ParsePushConfigReader config = new ParsePushConfigReader(getApplicationContext(), null, null);
50+
//
51+
//Parse.initialize(new Parse.Configuration.Builder(this)
52+
// .applicationId(config.getAppId())
53+
// .server(config.getServerUrl()) // The trailing slash is important, e.g., https://mydomain.com:1337/parse/
54+
// .build()
55+
//);
4756

48-
// Simple config reading for opensource parse-server:
49-
// 1st null to detect R.xml.config resource id, 2nd null indicates no custom config param
50-
//ParsePushConfigReader config = new ParsePushConfigReader(getApplicationContext(), null, null);
51-
//
52-
//Parse.initialize(new Parse.Configuration.Builder(this)
53-
// .applicationId(config.getAppId())
54-
// .server(config.getServerUrl()) // The trailing slash is important, e.g., https://mydomain.com:1337/parse/
55-
// .build()
56-
//);
57-
58-
//
59-
// Support parse.com and opensource parse-server
60-
// 1st null to detect R.xml.config
61-
ParsePushConfigReader config = new ParsePushConfigReader(getApplicationContext(), null, new String[] {"ParseClientKey"});
62-
if(config.getServerUrl().equalsIgnoreCase("PARSE_DOT_COM")){
63-
//
64-
//initialize for use with legacy parse.com
65-
Parse.initialize(this, config.getAppId(), config.getClientKey());
66-
} else {
67-
Log.d(LOGTAG, "ServerUrl " + config.getServerUrl());
68-
Log.d(LOGTAG, "NOTE: The trailing slash is important, e.g., https://mydomain.com:1337/parse/");
69-
Log.d(LOGTAG, "NOTE: Set the clientKey if your server requires it, otherwise it can be null");
70-
//
71-
// initialize for use with opensource parse-server
72-
Parse.initialize(new Parse.Configuration.Builder(this)
73-
.applicationId(config.getAppId())
74-
.server(config.getServerUrl())
75-
.clientKey(config.getClientKey())
76-
.build()
77-
);
78-
}
57+
//
58+
// Support parse.com and opensource parse-server
59+
// 1st null to detect R.xml.config
60+
ParsePushConfigReader config = new ParsePushConfigReader(getApplicationContext(), null,
61+
new String[] { "ParseClientKey" });
62+
if (config.getServerUrl().equalsIgnoreCase("PARSE_DOT_COM")) {
63+
//
64+
//initialize for use with legacy parse.com
65+
Parse.initialize(this, config.getAppId(), config.getClientKey());
66+
} else {
67+
Log.d(LOGTAG, "ServerUrl " + config.getServerUrl());
68+
Log.d(LOGTAG, "NOTE: The trailing slash is important, e.g., https://mydomain.com:1337/parse/");
69+
Log.d(LOGTAG, "NOTE: Set the clientKey if your server requires it, otherwise it can be null");
70+
//
71+
// initialize for use with opensource parse-server
72+
Parse.initialize(new Parse.Configuration.Builder(this).applicationId(config.getAppId())
73+
.server(config.getServerUrl()).clientKey(config.getClientKey()).build());
74+
}
7975

80-
Log.d(LOGTAG, "Saving Installation in background");
81-
//
82-
// save installation. Parse.Push will need this to push to the correct device
83-
ParseInstallation.getCurrentInstallation().saveInBackground(new SaveCallback() {
84-
@Override
85-
public void done(ParseException ex) {
86-
if (null != ex) {
87-
Log.e(LOGTAG, ex.toString());
88-
} else {
89-
Log.d(LOGTAG, "Installation saved");
90-
}
91-
}
92-
});
76+
Log.d(LOGTAG, "Saving Installation in background");
77+
//
78+
// save installation. Parse.Push will need this to push to the correct device
79+
ParseInstallation.getCurrentInstallation().saveInBackground(new SaveCallback() {
80+
@Override
81+
public void done(ParseException ex) {
82+
if (null != ex) {
83+
Log.e(LOGTAG, ex.toString());
84+
} else {
85+
Log.d(LOGTAG, "Installation saved");
86+
}
87+
}
88+
});
9389

94-
} catch(ParsePushConfigException ex){
95-
Log.e(LOGTAG, ex.toString());
96-
}
97-
}
90+
} catch (ParsePushConfigException ex) {
91+
Log.e(LOGTAG, ex.toString());
92+
}
93+
}
9894
}

src/android/ParsePushConfigException.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import java.lang.RuntimeException;
44

5-
public class ParsePushConfigException extends RuntimeException{
6-
public ParsePushConfigException(String message) {
7-
super(message);
8-
}
5+
public class ParsePushConfigException extends RuntimeException {
6+
public ParsePushConfigException(String message) {
7+
super(message);
8+
}
99
}

0 commit comments

Comments
 (0)