I am following this link, but after sending a message to the GCM API my Android receives an empty message (value set to null
).
This is my Django View, sending the message to the GCM API:
@csrf_exempt
def send_notification(request):
message = {"name": "Kousik","email": "kousik.tict@gmail.com"}
registration_ids = ['xxxxxxxxxxxxxxx','xxxxxxxxxxxxxxxxxx']
post_data = {"data":message,"registration_ids":registration_ids}
headers = {'Content-Type': 'application/json', 'Authorization':'key=xxxxxxxxx'}
import requests
post_response = requests.post(url='https://android.googleapis.com/gcm/send', data=simplejson.dumps(post_data), headers=headers)
to_json = {'status':str(post_response)}
return HttpResponse(simplejson.dumps(to_json), mimetype='application/json')
However, the traffic report shows no messages being sent at all:
Android Code receiving the GCM message:
static final String EXTRA_MESSAGE = "message";
private final BroadcastReceiver mHandleMessageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
for(String key: bundle.keySet()){
Log.d("gen", key+" - "+bundle.get(key));
}
String newMessage = intent.getExtras().getString(EXTRA_MESSAGE);
//newMessage comming NULL
// Waking up mobile if it is sleeping
WakeLocker.acquire(getApplicationContext());
// Showing received message
lblMessage.append(newMessage + "\n");
Toast.makeText(getApplicationContext(), "New Message: " + newMessage, Toast.LENGTH_LONG).show();
// Releasing wake lock
WakeLocker.release();
}
};
I put a break point here and I got the following:
Note the message
value in the hashmap, it is null
.