Fixes and Suggestions for Common Google Cloud Messaging Issues

Fixes and Suggestions for Common Google Cloud Messaging Issues

Google Cloud Messaging has indeed provided the means to improve information delivery from servers to mobile apps with the use of GCM cloud services. Reliability, speed and relevancy of information has been enhanced with the use of this open source data communication pathway. With the APIs for this service available free of cost to developers worldwide, a lot of ongoing work is being faced with certain issues that may seem a bit difficult to overcome.

We have compiled a list of the common issues which are being faced by developers currently. The resolution for the stated problems have been acquired from experts who have managed to find a viable solution to the challenges that are evident during GCM implementation of various mobile apps.

Issue #1: Inconsistent Data Encoding for Push-To-One-Device Vs Push-To-Multiple-Devices [Issue Type: Defect; Priority: Medium]

This issue in this case occurs with respect to UTF8 encoding where it seems to work for pushing notifications to a single device. However, when the same approach is used for pushing the notification to multiple devices, the UTF8 encoding does seem to apply.

The cause for this issue is that multi-device notifications did not make use of platform encoding so the data did not get processed as desired. This was a fault in the basic approach to multi-messages as this particular encoding was not used for it. But now the rectification has been made and it is possible to use UTF8 encoding for pushing notifications to multiple devices.

8-28-2014 6-52-26 PM

8-28-2014 6-55-49 PM

Issue #2: Missing Socket Timeout [Issue Type: Defect; Priority: Medium]

This issue has been reported for situations where a message is sent to the device but the network is blocked. In this case, the socket time seems to be missing as the expected outcome is the receipt of a TimeOutException after some time. But the process seems to go into an infinite loop of waiting.

An example of this case is the following code which was written by a developer in Sender.java

HttpURLConnection conn = getConnection(url);

conn.setDoOutput(true);

conn.setUseCaches(false);

conn.setFixedLengthStreamingMode(bytes.length);

conn.setRequestMethod(“POST”);

conn.setRequestProperty(“Content-Type”, contentType);

conn.setRequestProperty(“Authorization”, “key=” + key);

OutputStream out = conn.getOutputStream();

And get connection is defined as:

/**

* Gets an {@link HttpURLConnection} given an URL.

*/

protected HttpURLConnection getConnection(String url) throws IOException {

HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();

return conn;

}

The solution for this involves the use of the following command for blocking the network connection to android.googleapis.com, wherein iptables have been used to generate the desired outcome.

sudo iptables -I OUTPUT -d 173.194.70.95 -j DROP

By using this line, we would be able to block the code in conn.getOutputStream(). The problem needs to be tackled by adding a constant value for network timeout. You also need to add setConnectTimeout and setReadTimeout in the getConnection method in order to fix the missing socket timeout issue.

Issue #3: “Phone Does Not Support GCM” [Issue Type: Defect; Priority: Medium]

This error has been reported by some developers who come across this issue where the app is unable to fetch the registration ID from GCM in a restricted profile. However, when the same is tested from the admin profile, everything seems to work. The error message received in such a situation reads, “Incorrect phone registration with Google. This phone doesn’t currently support GCM. Constant Value: “PHONE_REGISTRATION_ERROR””.

Now this is a problem with the registration process itself where the device is unable to fetch the GCM registration ID and due to this, the communication pathway cannot be established. The most feasible solution to this problem is to uninstall the app from the device and then reinstalling it. This seems to work most of the time. In case it does not work, then you need to test it for specific issues that might have occurred in the methods used for the registration process.

About Vinita

Vinita Pariyani is an expert author for the iNewTechnology who has been writing about Smartphone, newest of the tech gadgets, apps and every update that pops up. She is a tech-savvy person who stays on top of cutting-edge technology/ gadgets.