android - GCM registration failed -
i working google push notifications. able retrieve reg id failing register mobile in server.can me going wrong
main activity:
gcmregistrar.checkdevice(this); // make sure manifest set - comment out line // while developing app, uncomment when it's ready. gcmregistrar.checkmanifest(this); //setcontentview(r.layout.activity_main); // mdisplay = (textview) findviewbyid(r.id.display); registerreceiver(mhandlemessagereceiver, new intentfilter(display_message_action)); final string regid = gcmregistrar.getregistrationid(this); mdisplay.append("reg id" + regid + " "); if (regid.equals("")) { // automatically registers application on startup. gcmregistrar.register(this, sender_id); //mdisplay.append("reg id" + regid + " "); } else { // device registered on gcm, check server. if (gcmregistrar.isregisteredonserver(this)) { // skips registration. //mdisplay.append(getstring(r.string.already_registered) + "\n"); // mdisplay.append("reg id" + regid + " "); } else { // try register again, not in ui thread. // it's necessary cancel thread ondestroy(), // hence use of asynctask instead of raw thread. // mdisplay.append("reg id" + regid + " "); final context context = this; mregistertask = new asynctask<void, void, void>() { @override protected void doinbackground(void... params) { boolean registered = serverutilities.register(context, regid, usernum); // @ point attempts register app // server failed, need unregister device // gcm - app try register again when // restarted. note gcm send // unregistered callback upon completion, // gcmintentservice.onunregistered() ignore it. if (!registered) { gcmregistrar.unregister(context); } return null; } @override protected void onpostexecute(void result) { mregistertask = null; } }; mregistertask.execute(null, null, null); } }
server utilities:
for (int = 1; <= max_attempts; i++) { log.d(tag, "attempt #" + + " register"); try { displaymessage(context, context.getstring( r.string.server_registering, i, max_attempts)); post(serverurl, params); gcmregistrar.setregisteredonserver(context, true); string message = context.getstring(r.string.server_registered); commonutilities.displaymessage(context, message); return true; } catch (ioexception e) { // here simplifying , retrying on error; in real // application, should retry on unrecoverable errors // (like http error code 503). log.e(tag, "failed register on attempt " + i, e); if (i == max_attempts) { break; } try { log.d(tag, "sleeping " + backoff + " ms before retry"); thread.sleep(backoff); } catch (interruptedexception e1) { // activity finished before complete - exit. log.d(tag, "thread interrupted: abort remaining retries!"); thread.currentthread().interrupt(); return false; } // increase backoff exponentially backoff *= 2; } }
server , sender id:
static final string server_url = "http://http://xxx.xxx.xxx.xxx:8080/sample"; /** * google api project id registered use gcm. */ static final string sender_id = "921198929963";
error log:
01-21 15:32:59.359 19009-19090/? e/gcmregistrar: internal error: retry receiver class not set yet 01-21 15:32:59.365 19009-19090/? e/regid: apa91bepjzzomsj10czbhxiaxmkyjmyzxtycusiho_bhmb-noqc-llu5usiaxzbf- iccjhtwgntysooxya9715u1kg4l2bv-zl3vz5dowk4mtyx9hdf5absaozmlo9ze_zdz-9ppnthi 01-21 15:32:59.988 19009-19090/? e/surakshagcm: failed register on attempt 1 01-21 15:33:02.215 19009-19090/? e/surakshagcm: failed register on attempt 2 01-21 15:33:06.647 19009-19090/? e/surakshagcm: failed register on attempt 3 01-21 15:33:14.913 19009-19090/? e/surakshagcm: failed register on attempt 4
kindly use latest gcm jar file. if error "internal error: retry receiver class not set yet", have older version of client gcm.jar. can download either source or updated gcm.jar gcm repository.
you may use tutorial guide, project contains client libraries , samples explore gcm apis: https://github.com/google/gcm
Comments
Post a Comment