private void callCloudCode() {
HashMap<String, Object> params = new HashMap<String, Object>();
params.put("channels", "The Matrix Channel");
params.put("data", "The Matrix Data");
ParseCloud.callFunctionInBackground("push", params, new FunctionCallback<String>() {
@Override
public void done(String object, ParseException e) {
if (e == null) {
// ratings is 4.5
Log.i(TAG, "Successfully called cloud code: " + object);
} else {
Log.e(TAG, "Could not call cloud code: " + e.getMessage());
}
}
});
}
ParseInstallation.getCurrentInstallation().saveInBackground();
HashMap<String, Object> params = new HashMap<String, Object>();
HashMap<String, Object> data = new HashMap<String, Object>();
params.put("channels", ["The Matrix Channel"]);
data.put("alert", "The Matrix Data");
params.put("data", data);
params.put("channels", ["The Matrix Channel"]); // <-- compiler error wrong array
params.put("channels", new String[] {"The Matrix Channel"}); // <-- ParseException wrong channel type
params.put("channels", new String[] {"The Matrix Channel"}); // <-- ParseException wrong channel type
Parse.Cloud.define('pushme', function (request, response) { // THIS METHOD NO LONGER WORKS // Parse.Cloud.useMasterKey(); Parse.Push.send({ channels: [ "channel_name" ], data: { alert: "Alert message" } }, { // ADD THE `useMasterKey` TO THE OPTIONS OBJECT useMasterKey: true, success: function () { response.success('Success!'); }, error: function (error) { response.error('Error! ' + error.message); } }); });
The call is working:
04-07 10:35:39.262 26911-26911/com.directions.sample I/MainActivity: Successfully called cloud code: Success!
BUT i have still no notification on my device.
May i ask how the GCM Configuration in the AndroidManifest should look like?
this is mine:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.directions.sample" >
<!-- Copied from Google Maps Library/AndroidManifest.xml. -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- External storage for caching. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Maps API needs OpenGL ES 2.0. -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<!-- Creates a custom permission so only this app can receive its messages. -->
<permission
android:name="com.directions.sample.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.directions.sample.permission.C2D_MESSAGE" />
<!-- This app has permission to register and receive data message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="MY_KEY"/>
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.parse.push.notification_icon"
android:resource="@mipmap/ic_launcher" />
</application>
</manifest>
Thank you very much!
Alex
In the back4app logs console im now getting this:
GCM request and response {"request":{"params":{"priority":"normal","data":{"time":"2016-04-07T15:33:06.185Z","push_id":"SkMs7ZTSgi","data":"{\"title\":\"Alex 954977199129\",\"message\":\"hey msg\"}"}}},"response":{"multicast_id":5557131503309148000,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"MismatchSenderId"}]}}
Like i said i tried all API-Keys.
The user installation is saved fine with the pushType "gcm".
Do you have an advice for me?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.directions.sample">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:protectionLevel="signature"
android:name="com.directions.sample.permission.C2D_MESSAGE" />
<uses-permission android:name="com.directions.sample.permission.C2D_MESSAGE" />
<!-- Other permissions for your app... -->
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity android:name=".Main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Parse setup -->
<meta-data
android:name="com.parse.APPLICATION_ID"
android:value="YOUR_APPLICATION_ID" />
<meta-data
android:name="com.parse.CLIENT_KEY"
android:value="YOUR_CLIENT_KEY" />
<!-- GCM setup -->
<meta-data
android:name="com.parse.push.gcm_sender_id"
android:value="id:YOUR_SENDER_ID" />
<!-- The following service and broadcast receiver definitions must come immediately
before the closing </application> tag -->
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.directions.sample" />
</intent-filter>
</receiver>
</application>
</manifest>
// Parse setup
Parse.initialize(this);
// Update Installation
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("GCMSenderId", "YOUR_SENDER_ID");
installation.saveInBackground();
<!-- GCM setup -->
<meta-data
android:name="com.parse.push.gcm_sender_id"
android:value="id:YOUR_SENDER_ID" />
instead of
<!-- GCM setup -->
<meta-data
android:name="com.parse.push.gcm_sender_id"
android:value="YOUR_SENDER_ID" />
// Update Installation
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("GCMSenderId", "YOUR_SENDER_ID");
installation.saveInBackground();
//instead of
ParseInstallation.getCurrentInstallation().saveInBackground();