java - Issue with the GCM in android -


in android application implementing push notification.its first time using gcm. in application need reference code enter application after google+ login.if user referral enter code successfully, referred user receive notification following fields:

$message = array("type" => "ref","title" => "joined on application"); 

but don't know how implement logic in application.i tried following per tutorial..but not working

mainactivity.java

 @override         protected void onpostexecute(void avoid) {             dialog.dismiss();             log.d("jspn ", json);               if (json != null) {                if (status==1) {                   if(reference_code.equals("0"))                   {   final dialog dialog = new dialog(mainactivity.this);                       dialog.setcontentview(r.layout.popup);                       button id_save = (button)dialog.findviewbyid(r.id.save_btn);                       final edittext e_ref = (edittext) dialog.findviewbyid(r.id.e_ref);                       button     dialog_cancel = (button) dialog.findviewbyid(r.id.btnc);                          id_save.setonclicklistener(new view.onclicklistener() {                           @override                           public void onclick(view v) {                               reference_id=   e_ref.gettext().tostring();                               new getref().execute();                           }                       });                       dialog_cancel.setonclicklistener(new view.onclicklistener() {                           @override                           public void onclick(view v) {                               dialog.dismiss();                           }                       });                       dialog.show();                    }                   else                   {                       intent in = new intent(mainactivity.this, homeactivity.class);                       startactivity(in);                   }                }   } else {                      toast.maketext(mainactivity.this, "login failed", toast.length_short).show();                  }              }            @override         protected void doinbackground(void... params) {             string url = "";               url=urls.baseurl+"mobile_api.php?action=userlogin&user_name="+urlencoder.encode(plusname)+"&image="+plusimage+"&email="+gmail+"&gcm_id="+deviceid;  url=urls.baseurl+"mobile_api.php?action=userlogin&user_name="+plusname+"&image="+plusimage+"&email="+g_mail+"&gcm_id="+deviceid;       jsonreader reader=new jsonreader();             json=reader.getjsonget(url);              if (json != null) {                 try {                     jsonobject object = new jsonobject(json);                     if (object.getjsonarray("posts").getjsonobject(0).getint("status") != 0) {                         status=object.getjsonarray("posts").getjsonobject(0).getint("status");                         accesstoken = object.getjsonarray("posts").getjsonobject(0).getstring("access_token");                         userid = object.getjsonarray("posts").getjsonobject(0).getstring("user_id");                         reference_code = object.getjsonarray("posts").getjsonobject(0).getstring("ref_by");                          sharedpreferences.editor edit = m_pref.edit();                         edit.putint("userid", integer.parseint(userid));                         edit.putstring("accesstoken", accesstoken);                         edit.commit();                     }                  } catch (jsonexception e) {                     e.printstacktrace();                 }             }              return null;         }  public class getref extends asynctask<void, void, void> {         string json = null;         progressdialog dialog;         string message; int status_ref;         @override         protected void onpreexecute() {             dialog = new progressdialog(mainactivity.this);             dialog.setmessage("loading contest...");             dialog.setcanceledontouchoutside(false);             dialog.setcancelable(false);             dialog.show();             super.onpreexecute();         }          @override         protected void onpostexecute(void avoid) {             dialog.dismiss();             if (status_ref == 1)             {                 toast.maketext(getapplicationcontext(),message,toast.length_short).show();                 intent in = new intent(mainactivity.this, homeactivity.class);                 startactivity(in);                 finish();             }             else {                 toast.maketext(getapplicationcontext(),"error",toast.length_short).show();              }         }          @override         protected void doinbackground(void... params) {             string url = urls.baseurl +"mobile_api.php?action=referal_update&access_token="+accesstoken+"&user_id="+userid+"&referal_code="+reference_id;             jsonreader reader=new jsonreader();             json=reader.getjsonget(url);              if (json != null) {                 try {                     jsonobject object = new jsonobject(json);                     if (object.getjsonarray("posts").getjsonobject(0).getint("status") != 0) {                         status_ref=object.getjsonarray("posts").getjsonobject(0).getint("status");                         message = object.getjsonarray("posts").getjsonobject(0).getstring("msg");                         //contestname = object.getjsonarray("posts").getjsonobject(0).getstring("contest_name");                         log.d("status_reference",status_ref+"");                      }                  } catch (jsonexception e) {                     e.printstacktrace();                 }             }              return null;         } 

also

public class gcmintentservice extends intentservice {      public static final int notification_id = 02121;     private notificationmanager mnotificationmanager;     string mes;      string tag = "chat";     intent notificationintent = null;     @suppresswarnings("unused")     private handler handler;     sharedpreferences pref;     sharedpreferences.editor edit;      // list<com.wat.tosupport.chat.freshim.models.userdetail> details;      public gcmintentservice() {         super("gcmmessagehandler");     }      @override     public void oncreate() {         // todo auto-generated method stub         super.oncreate();         handler = new handler();         pref = preferencemanager                 .getdefaultsharedpreferences(getapplicationcontext());         edit = pref.edit();      }      @override     protected void onhandleintent(intent intent) {         bundle extras = intent.getextras();         log.d("extras", extras.tostring());         @suppresswarnings("unused")         googlecloudmessaging gcm = googlecloudmessaging.getinstance(this);          string messagetype = intent.getextras().getstring("type");         if (messagetype != null) {               if (messagetype.equalsignorecase("referal")) {                 string messagetitle = intent.getextras().getstring("title");                 generatenotification(messagetitle);             }          }         gcmbroadcastreceiver.completewakefulintent(intent);      }      private void generatenotification(string messagetitle) {         mnotificationmanager = (notificationmanager)                 .getsystemservice(context.notification_service);         notificationcompat.builder mbuilder = new notificationcompat.builder(                 this)                 .setsmallicon(r.mipmap.ic_launcher)                 .setcontenttitle(getresources().getstring(r.string.app_name))                 .setstyle(                         new notificationcompat.bigtextstyle().bigtext(messagetitle))                 .setticker(messagetitle).setcontenttext(messagetitle).setautocancel(true);          // play default notification sound         mbuilder.setdefaults(notification.default_sound                 | notification.flag_auto_cancel);         intent in = new intent(getapplicationcontext(), mainactivity.class);         in.addflags(intent.flag_activity_clear_top);         in.addflags(intent.flag_activity_clear_task);         in.addflags(intent.flag_activity_new_task);         in.setflags(intent.flag_activity_clear_top);         in.setflags(intent.flag_activity_clear_task);         in.setflags(intent.flag_activity_new_task);          pendingintent contentintent = pendingintent.getactivity(this, 0, in, 0);          mbuilder.setcontentintent(contentintent);         mnotificationmanager.notify(notification_id, mbuilder.build());     } 

please me!!

first of need manage device id's of both user device , referral device , please make sure gets generated, on basis of these id's can push messages on respective device.

so once logged in via google plus need match referral code i.e need match referral code called , invoke user device id , can achieve this... ! may want exactly...!


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -