Confuse of Push Notification in Android -


i followed push notification tutorial.

when finish tutorial, found out 2 classes did not use authenticationutil , messageutil.

moreover, google login, link seem unworkable. second, token id android device or account only? thought push notification push message token id of android device.

on others hand, found out bundle.putextra(key, value), keys did not use it. example put "app" in c2dmregistrationreceiver() did not key.

in sendregistrationidtoserver(), seem never being call out.

i being confused tutorial push notification.

who can guide me or give me workable tutorial or example push notification?

i pro point out what's wrong.

this registration id

public static final string[] registration_id = {         "apa91bfv6mwoah0unop69pz2likpsbuhsheniupzh44_6gdgkzvclvoh_nm31emzmvlzi-saifwp4izae72dswkih3gad0rqyppm9zo0arwmnoxfyyyrel_kpq9qd_p0broclt12rha4ymk0cbt00cmpsbshiwyxig",         "apa91bewmxgvs7znbkc4p0n4dotem73dtihnqgbop8gxhf2svw-fgltugdgs1fh2s4kvn1wqhbmnjeiziej9f1nnpqs3nwekgbb7ibypkjq4xmn4z7uzkjzqqukgd8jw--awfqy5mcinbto9gal_87_u5wkiq-kx3g",         "apa91bh63zgxn1x_mz56uzrlrpffvmilaisqxvbutmuhp2o_mt_vu9ork_edxkhlml-pzskjkeqdk8ekv5hvxbpdk1vva3wtmqspzfhxzebtnirwrqivvrf7hl835rdc4t2e8ekubj1dx2ta0oxy5py3xlhkyb1sbg",         "apa91bgqt5wo6euamdqt5r9tlgbksx6gn2w6r-rjrrxz5t5v3j87flcqryfsajmmngxupve-fwzydrmvyyu63twnyohdmpjykkxoxs8vx6p_fplfq__ufr_hekwqgospeuc6bfc8fhbmpgn3ft9l-bfrghjwwk79jw"}; 

messageutil

public static int sendmessage(string auth_token, string registrationid,         string message, string title) throws ioexception {      stringbuilder postdatabuilder = new stringbuilder();     postdatabuilder.append(param_registration_id).append("=")             .append(registrationid);     postdatabuilder.append("&").append(param_collapse_key).append("=")             .append("0");     postdatabuilder.append("&").append("data.payload").append("=")             .append(urlencoder.encode(message, utf8));     postdatabuilder.append("&").append("data.title").append("=")             .append(urlencoder.encode(title, utf8));      byte[] postdata = postdatabuilder.tostring().getbytes(utf8);      // hit dm url.      url url = new url("https://android.clients.google.com/c2dm/send");     httpsurlconnection             .setdefaulthostnameverifier(new customizedhostnameverifier());     httpsurlconnection conn = (httpsurlconnection) url.openconnection();     conn.setdooutput(true);     conn.setusecaches(false);     conn.setrequestmethod("post");     conn.setrequestproperty("content-type",             "application/x-www-form-urlencoded;charset=utf-8");     conn.setrequestproperty("content-length",             integer.tostring(postdata.length));     conn.setrequestproperty("authorization", "googlelogin auth="             + auth_token);      outputstream out = conn.getoutputstream();     out.write(postdata);     out.close();      int responsecode = conn.getresponsecode();     return responsecode; }  private static class customizedhostnameverifier implements hostnameverifier {     public boolean verify(string hostname, sslsession session) {         return true;     } } 

messagesender

public static void main(string[] args) throws ioexception {     string token = authenticationutil.gettoken(securestorage.user,             securestorage.password);      (int = 0; < serverconfiguration.registration_id.length; i++) {         messageutil.sendmessage(token,                 serverconfiguration.registration_id[i], "12358",                 "印尼羽賽:馬2單1雙止步入選賽");         system.out.println(serverconfiguration.registration_id[i]                 .tostring());     }     system.out.println(token);  } 

you should follow this tutorial android c2dm implementation.

for server, use anything, code sample available on internet. server used .net library called "c2dm sharp"

the process simple like...

  • first register google email c2dm on - https://developers.google.com/android/c2dm/signup
  • run android application on android 2.2 or higher , send registrationid can in "c2dmreceiver" or id writting in log
  • use server code, testing purpose paste registrationid in server code , ready go.

the basic flow of c2dm ... register phone c2dm -> get registrationid -> send registrationid server -> server usees google id auth token -> server use registrationid , auth token send message.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -