I've been following the Set Up a GCM Client App tutorial and tried to understand the demo app they provided, but I couldn't understand how to send push notification with this service.
The above guide leads me to a "Generating InstanceID token" screen with never-ending ProgressBar. This program source can be obtained here: https://github.com/googlesamples/google-services/tree/master/android/gcm/app/src/main
After using the above source code I've tried next to Simple Downstream messaging, this: https://developers.google.com/cloud-messaging/downstream in order to send push to the app users.
I couldn't understand how I'm supposed to send my app users notifications with it.
I have a server and I'm great with PHP, What is left to do in order to send push notification to my application users using the GCM?
Finally managed to get the message to a TextView! How do make it into push?
public class GcmService extends GcmListenerService {
@Override
public void onMessageReceived(String from, Bundle data) {
JSONObject jsonObject = new JSONObject();
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));
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onDeletedMessages() {
sendNotification("Deleted messages on server");
}
@Override
public void onMessageSent(String msgId) {
sendNotification("Upstream message sent. Id=" + msgId);
}
@Override
public void onSendError(String msgId, String error) {
sendNotification("Upstream message send error. Id=" + msgId + ", error" + error);
}
private void sendNotification(final String msg) {
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
if (MainActivity.mTextView != null) {
MainActivity.mTextView.setText(msg);
}
}
});
}
}