Skip to content

Commit 16feb9a

Browse files
committed
Upgrade demo
Fix AndroidManifest Update README.md file Fix
1 parent 6584f34 commit 16feb9a

File tree

9 files changed

+132
-76
lines changed

9 files changed

+132
-76
lines changed

README.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,52 @@
22

33
...
44

5-
This source code was originally created by Vishal Kapoor as part of our Jan Android bootcamp.
5+
This source code was originally created by Vishal Kapoor as part of our Jan Android bootcamp.
6+
7+
### Setup
8+
9+
1. Update `res/strings.xml` and update your GCM sender ID.
10+
11+
2. Update your `PARSE_CLOUD_SERVER_URL` in `MainApp.java`.
12+
13+
3. Update your `PARSE_APP_ID` in `MainApp.java`.
14+
15+
Make sure you have your Parse cloud server configured with the `pushChannelTest` function:
16+
17+
```javascript
18+
19+
Parse.Cloud.define('pushChannelTest', function(request, response) {
20+
21+
// request has 2 parameters: params passed by the client and the authorized user
22+
var params = request.params;
23+
var user = request.user;
24+
25+
// extract out the channel to send
26+
var action = params.action;
27+
var message = params.message;
28+
var customData = params.customData;
29+
30+
// use to custom tweak whatever payload you wish to send
31+
var pushQuery = new Parse.Query(Parse.Installation);
32+
pushQuery.equalTo("deviceType", "android");
33+
34+
var payload = {"data": {
35+
"alert": message,
36+
"action": action,
37+
"customdata": customData}
38+
};
39+
40+
// Note that useMasterKey is necessary for Push notifications to succeed.
41+
42+
Parse.Push.send({
43+
where: pushQuery, // for sending to a specific channel data: payload,
44+
}, { success: function() {
45+
console.log("#### PUSH OK");
46+
}, error: function(error) {
47+
console.log("#### PUSH ERROR" + error.message);
48+
}, useMasterKey: true});
49+
50+
response.success('success');
51+
});
52+
53+
```

app/build.gradle

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 19
5-
buildToolsVersion "21.1.2"
4+
compileSdkVersion 23
5+
buildToolsVersion "23.0.1"
66

77
defaultConfig {
88
applicationId "com.test"
9-
minSdkVersion 19
10-
targetSdkVersion 19
9+
minSdkVersion 16
10+
targetSdkVersion 23
1111
}
1212

1313
buildTypes {
@@ -19,6 +19,9 @@ android {
1919
}
2020

2121
dependencies {
22-
compile 'com.android.support:support-v4:19.1.0'
23-
compile files('libs/Parse-1.2.3.jar')
22+
compile 'com.android.support:support-v4:23.1.0'
23+
compile 'com.parse:parse-android:1.13.0'
24+
compile 'com.parse.bolts:bolts-android:1.4.0'
25+
compile 'com.parse:parseinterceptors:0.0.2'
26+
compile 'com.facebook.stetho:stetho:1.3.0'
2427
}

app/libs/Parse-1.2.3.jar

-467 KB
Binary file not shown.

app/src/main/AndroidManifest.xml

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,38 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.test"
2+
<manifest package="com.test"
3+
xmlns:android="http://schemas.android.com/apk/res/android"
44
android:versionCode="1"
5-
android:versionName="1.0" >
5+
android:versionName="1.0">
66

77
<uses-sdk
8-
android:minSdkVersion="19"
9-
android:targetSdkVersion="19" />
8+
android:minSdkVersion="23"
9+
android:targetSdkVersion="23" />
1010

1111
<uses-permission android:name="android.permission.INTERNET" />
1212
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
1313
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
14+
<uses-permission android:name="android.permission.WAKE_LOCK" />
1415
<uses-permission android:name="android.permission.VIBRATE" />
16+
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
17+
18+
<!--
19+
IMPORTANT: Change "com.codepath.parseportpush.permission.C2D_MESSAGE" in the lines below
20+
to match your app's package name + ".permission.C2D_MESSAGE".
21+
-->
22+
<permission
23+
android:name="com.test.permission.C2D_MESSAGE"
24+
android:protectionLevel="signature" />
25+
<uses-permission android:name="com.test.permission.C2D_MESSAGE" />
1526

1627
<application
17-
android:name="com.test.MainApp"
28+
android:name="com.test.MainApp"
1829
android:allowBackup="true"
1930
android:icon="@drawable/ic_launcher"
2031
android:label="@string/app_name"
21-
android:theme="@style/AppTheme" >
32+
android:theme="@style/AppTheme">
2233
<activity
2334
android:name="com.test.MainActivity"
24-
android:label="@string/app_name" >
35+
android:label="@string/app_name">
2536
<intent-filter>
2637
<action android:name="android.intent.action.MAIN" />
2738
<category android:name="android.intent.category.LAUNCHER" />
@@ -30,23 +41,33 @@
3041
<activity
3142
android:name="com.test.ShowPopUp"
3243
android:label="@string/app_name"
33-
android:theme="@android:style/Theme.Holo.Light.Dialog" >
34-
</activity>
44+
android:theme="@android:style/Theme.Holo.Light.Dialog"></activity>
45+
46+
<meta-data
47+
android:name="com.parse.push.gcm_sender_id"
48+
android:value="@string/gcm_sender_id" />
3549

3650
<service android:name="com.parse.PushService" />
3751

38-
<receiver android:name="com.parse.ParseBroadcastReceiver" >
52+
<receiver
53+
android:name="com.test.MyCustomReceiver"
54+
android:exported="false">
3955
<intent-filter>
40-
<action android:name="android.intent.action.BOOT_COMPLETED" />
41-
<action android:name="android.intent.action.RECEIVE_BOOT_COMPLETED" />
42-
<action android:name="android.intent.action.USER_PRESENT" />
56+
<action android:name="com.parse.push.intent.RECEIVE" />
57+
<action android:name="com.parse.push.intent.DELETE" />
58+
<action android:name="com.parse.push.intent.OPEN" />
4359
</intent-filter>
4460
</receiver>
45-
<receiver android:name="com.test.MyCustomReceiver" >
61+
<receiver
62+
android:name="com.parse.GcmBroadcastReceiver"
63+
android:permission="com.google.android.c2dm.permission.SEND">
4664
<intent-filter>
47-
<action android:name="android.intent.action.BOOT_COMPLETED" />
48-
<action android:name="android.intent.action.USER_PRESENT" />
49-
<action android:name="SEND_PUSH" />
65+
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
66+
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
67+
<!--
68+
IMPORTANT: Change "com.test" to match your app's package name.
69+
-->
70+
<category android:name="com.test" />
5071
</intent-filter>
5172
</receiver>
5273
</application>

app/src/main/java/com/test/MainActivity.java

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package com.test;
22

33

4-
import org.json.JSONException;
5-
import org.json.JSONObject;
4+
import com.parse.ParseCloud;
65

76
import android.app.Activity;
87
import android.content.BroadcastReceiver;
@@ -17,10 +16,7 @@
1716
import android.widget.Button;
1817
import android.widget.Toast;
1918

20-
import com.parse.ParseInstallation;
21-
import com.parse.ParsePush;
22-
import com.parse.ParseQuery;
23-
import com.parse.PushService;
19+
import java.util.HashMap;
2420

2521
public class MainActivity extends Activity implements OnClickListener {
2622

@@ -39,8 +35,6 @@ protected void onCreate(Bundle savedInstanceState) {
3935
super.onCreate(savedInstanceState);
4036
setContentView(R.layout.activity_main);
4137

42-
PushService.setDefaultPushCallback(this, MainActivity.class);
43-
4438
push = (Button)findViewById(R.id.senPushB);
4539
push.setOnClickListener(this);
4640
}
@@ -68,26 +62,12 @@ public boolean onCreateOptionsMenu(Menu menu) {
6862

6963
@Override
7064
public void onClick(View v) {
71-
72-
JSONObject obj;
73-
try {
74-
obj = new JSONObject();
75-
obj.put("alert", "hello!");
76-
obj.put("action", MyCustomReceiver.intentAction);
77-
obj.put("customdata","My message");
78-
79-
ParsePush push = new ParsePush();
80-
ParseQuery query = ParseInstallation.getQuery();
81-
82-
// Push the notification to Android users
83-
query.whereEqualTo("deviceType", "android");
84-
push.setQuery(query);
85-
push.setData(obj);
86-
push.sendInBackground();
87-
} catch (JSONException e) {
88-
89-
e.printStackTrace();
90-
}
65+
66+
HashMap<String, String> payload = new HashMap<>();
67+
payload.put("message", "hello!");
68+
payload.put("action", "SEND_PUSH");
69+
payload.put("customData", "My message");
70+
ParseCloud.callFunctionInBackground("pushChannelTest", payload);
9171
}
9272

9373

app/src/main/java/com/test/MainApp.java

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,31 @@
22

33
import com.parse.Parse;
44
import com.parse.ParseInstallation;
5+
import com.parse.interceptors.ParseLogInterceptor;
6+
import com.parse.interceptors.ParseStethoInterceptor;
57

68
import android.app.Application;
79

810
public class MainApp extends Application {
9-
10-
private static final String parse_app_id = "YOUR_APP_ID";
11-
private static final String parse_client_key = "YOUR_CLIENT_KEY";
12-
13-
@Override
14-
public void onCreate() {
15-
super.onCreate();
16-
17-
Parse.initialize(this, parse_app_id, parse_client_key);
18-
ParseInstallation.getCurrentInstallation().saveInBackground();
19-
}
11+
12+
private static final String PARSE_APP_ID = "myAppId";
13+
private static final String PARSE_CLOUD_SERVER_URL = "http://myherokuapp.herokuapp.com/parse";
14+
15+
// Make sure to update gcm_sender_id in strings.xml!!
16+
17+
@Override
18+
public void onCreate() {
19+
super.onCreate();
20+
21+
Parse.initialize(new Parse.Configuration.Builder(this)
22+
.applicationId(PARSE_APP_ID)
23+
.clientKey(null) // no client key needed in Parse open source
24+
.server(PARSE_CLOUD_SERVER_URL)
25+
.addNetworkInterceptor(new ParseStethoInterceptor())
26+
.addNetworkInterceptor(new ParseLogInterceptor())
27+
.build());
28+
29+
// Need to register GCM token
30+
ParseInstallation.getCurrentInstallation().saveInBackground();
31+
}
2032
}

app/src/main/java/com/test/MyCustomReceiver.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.test;
22

3-
import java.util.Iterator;
4-
53
import org.json.JSONException;
64
import org.json.JSONObject;
75

@@ -13,9 +11,11 @@
1311
import android.support.v4.content.LocalBroadcastManager;
1412
import android.util.Log;
1513

14+
import java.util.Iterator;
15+
1616
public class MyCustomReceiver extends BroadcastReceiver {
1717
private static final String TAG = "MyCustomReceiver";
18-
public static final String intentAction = "SEND_PUSH";
18+
public static final String intentAction = "com.parse.push.intent.RECEIVE";
1919

2020
@Override
2121
public void onReceive(Context context, Intent intent) {

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
<string name="app_name">PushNotificationDemo</string>
55
<string name="hello_world">Hello world!</string>
66
<string name="menu_settings">Settings</string>
7-
7+
<string name="gcm_sender_id">id:123</string>
88
</resources>

app/src/main/res/values/strings.xml~

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)