I implemented the app engine module with Google Cloud Messaging, the devices are registrated succesfully and I deployed it live already. My question is, by doing a RESTful API with this integration, do I need to make a server side code, for sending push notifications, or can I send them through the client-side part?
Here´s my Android Manifest code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="myPackage">
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-feature
android:name="android.hardware.Camera2"
android:required="true" />
<!-- This filters devices that don't support sip -->
<uses-feature
android:name="android.hardware.sip.voip"
android:required="true" />
<uses-feature
android:name="android.hardware.wifi"
android:required="true" />
<uses-feature
android:name="android.hardware.microphone"
android:required="true" />
<receiver
android:name=".IncomingCallReceiver"
android:label="Call Receiver" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- [START gcm_permission] -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" >
<!-- [END gcm_permission] -->
<permission
android:name="myPackage.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="myPackage.permission.C2D_MESSAGE" />
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity android:name=".LogInActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_app_id" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
<activity android:name=".MainActivity" />
<activity
android:name=".Messaging.Activities.FriendsRequestsActivity"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".Messaging.Activities.ChatActivity"
android:launchMode="singleTop"
android:parentActivityName=".MainActivity"
android:screenOrientation="portrait"
android:theme="@style/ChatTheme"
android:windowSoftInputMode="adjustResize|stateHidden">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="myPackage" />
</intent-filter>
</receiver>
<service
android:name=".Utils.InstanceIDListener"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID" />
</intent-filter>
</service>
<service
android:name="myPackage.Utils.RegistrationIntent"
android:exported="false"></service>
<service
android:name="myPackage.Utils.GcmListener"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
</application>
</manifest>`
This is my GcmListener that receives that is supposed to be receiving the message:
public class GcmListener extends GcmListenerService {
private static final String TAG = "Push";
/**
* Called when message is received.
*
* @param from SenderID of the sender.
* @param data Data bundle containing message data as key/value pairs.
* For Set of keys use data.keySet().
*/
// [START receive_message]
@Override
public void onMessageReceived(String from, Bundle data) {
JSONObject jsonObject = new JSONObject();
Log.d(TAG, "Push received");
Set<String> keys = data.keySet();
for (String key : keys) {
try {
jsonObject.put(key, data.get(key));
} catch (JSONException e) {
e.printStackTrace();
}
}
try {
sendNotification("Received: " + jsonObject.toString(5));//TODO Forward to be written
} catch (JSONException e) {
e.printStackTrace();
}
if (from.startsWith("/topics/")) {
// message received from some topic.
} else {
// normal downstream message.
}
// [START_EXCLUDE]
/**
* Production applications would usually process the message here.
* Eg: - Syncing with server.
* - Store message in local database.
* - Update UI.
*/
/**
* In some cases it may be useful to show a notification indicating to the user
* that a message was received.
*/
//sendNotification(message); TODO create the correct notification to be showed to the user
// [END_EXCLUDE]
}
}
The sendNotification method is not written yet, but I put a log to check if the message was received, and I get nothing,I honestly think I used the wrong API_KEY from the Google Developers Console, I am using the: Server key (auto created by Google Service), or maybe the order of the declarations of the services in the manifest. Those are the only things that I can think of that could be causing the app not to get the push message