android - How to display lat-lng points on map when open notification ? -


i developing 1 application in want show map when open notification, received notification when open notification not open map lat long values.

gcmintent service class

 public class gcmintentservice extends intentservice{  context context; public static int notify_no=0;  //system.currenttimemillis();  private notificationmanager mnotificationmanager; notificationcompat.builder builder; public static final string tag = "gcm notification";  public gcmintentservice() {     super("gcmintentservice");     // todo auto-generated constructor stub }  @override protected void onhandleintent(intent intent) {     // todo auto-generated method stub     bundle extras = intent.getextras();     string msg = intent.getstringextra("message");     googlecloudmessaging gcm = googlecloudmessaging.getinstance(this);     string messagetype = gcm.getmessagetype(intent);        if (!extras.isempty()) {           if (googlecloudmessaging.                     message_type_send_error.equals(messagetype)) {                // sendnotification(regiddto.reg_id,"send error: " + extras.tostring());              sendnotification(this,msg);             } else if (googlecloudmessaging.                     message_type_deleted.equals(messagetype)) {                // sendnotification(regiddto.reg_id,"deleted messages on server: " +                //         extras.tostring());                 sendnotification(this,msg);             // if it's regular gcm message, work.             } else if (googlecloudmessaging.                     message_type_message.equals(messagetype)) {                 // loop represents service doing work.                 (int i=0; i<5; i++) {                     log.i(tag, "working... " + (i+1)                             + "/5 @ " + systemclock.elapsedrealtime());                     try {                         thread.sleep(500);                     } catch (interruptedexception e) {                     }                 }                 log.i(tag, "completed work @ " + systemclock.elapsedrealtime());                 // post notification of received message.                 //sendnotification("received: " + extras.tostring());                // sendnotification(regiddto.reg_id,msg);                 sendnotification(this,msg);                 log.i(tag, "received: " + extras.tostring());             }         }      gcmbroadcastreceiver.completewakefulintent(intent); }   private static void sendnotification(context context,string message) {     int icon = r.drawable.ic_stat_gcm;     long when = system.currenttimemillis();     notificationcompat.builder nbuilder;     uri alarmsound = ringtonemanager             .getdefaulturi(ringtonemanager.type_notification);     nbuilder = new notificationcompat.builder(context)             .setsmallicon(r.drawable.ic_launcher)             .setcontenttitle("header")             .setlights(color.blue, 500, 500).setcontenttext(message)             .setautocancel(true).setticker("notification traffic")             .setvibrate(new long[] { 100, 250, 100, 250, 100, 250 })             .setsound(alarmsound);     string consumerid = null;     integer position = null;            // write click event here        intent resultintent = new intent(context, showmapactivity.class);         resultintent.putextra("message", message);       // resultintent.setdata(uri.parse("content://"+when));   pendingintent resultpendingintent = pendingintent.getactivity(context,         notify_no, resultintent, pendingintent.flag_update_current);         // show max number of notifications here if (notify_no < 9) {     notify_no = notify_no + 1; } else {     notify_no = 0; }  nbuilder.setcontentintent(resultpendingintent);  notificationmanager nnotifymgr = (notificationmanager) context         .getsystemservice(context.notification_service);  nnotifymgr.notify(notify_no + 2, nbuilder.build()); }  } 

showmap class

 public class showmapactivity extends fragmentactivity implements locationlistener {       googlemap _googlemap;      latlng myposition;     locationmanager locationmanger;       textview addresstextview,ctimetextview;          jsonobject json;         gcmintentservice serv;         context mcontext;      intent noticeintent = getintent();      string lat;     string lng;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_show_map);      //addresstextview = (textview)findviewbyid(r.id.addressid);     //ctimetextview   = (textview)findviewbyid(r.id.ctimeid);      string message = noticeintent.getextras().getstring("message");      try {         json = new jsonobject(message);         lat = json.getstring("lat");           log.e("lloonngg", ""+lat);         lng = json.getstring("lng");           log.e("lloonngg", ""+lng);         string adr = json.getstring("address");         addresstextview.settext(adr);           string ctime = json.getstring("ctime");         ctimetextview.settext(ctime);       } catch (jsonexception e) {         // todo auto-generated catch block         e.printstacktrace();     }       _googlemap = ((supportmapfragment) getsupportfragmentmanager().findfragmentbyid(             r.id.map)).getmap();       locationmanager service = (locationmanager)getsystemservice(location_service);      boolean enablegps = service.isproviderenabled(locationmanager.gps_provider);     boolean enablewifi= service.isproviderenabled(locationmanager.network_provider);      if(!enablegps || !enablewifi){         toast.maketext(showmapactivity.this, "gps signal not found", toast.length_long).show();         intent intent = new intent(settings.action_location_source_settings);         startactivity(intent);     }      locationmanger = (locationmanager) getsystemservice(context.location_service);     criteria criteria = new criteria();     string provider = service.getbestprovider(criteria, true);       service.requestlocationupdates(provider, 0, 0, this);       if(_googlemap==null){         toast.maketext(getapplicationcontext(), "google map not available", toast.length_long).show();         } }  @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.show_map, menu);     return true; }  @override public void onlocationchanged(location location) {     // todo auto-generated method stub      //locationmanger.requestlocationupdates(locationmanager.network_provider, 0, 0, this);     _googlemap.clear();     arraylist<hashmap<string, string>> arl = (arraylist<hashmap<string, string>>)              getintent().getserializableextra("arraylist");       /*if(location!=null){         double latitude = location.getlatitude();         double langitude = location.getlongitude();          latlng latlang = new latlng(latitude, langitude);         //latlngbounds curscreen =                 _googlemap.getprojection().getvisibleregion().latlngbounds;         //curscreen.contains(latlang);         myposition = new latlng(latitude, langitude);               // show current location          _googlemap.movecamera(cameraupdatefactory.newlatlng(myposition));          _googlemap.addmarker(new           markeroptions().position(myposition).title("start"));      }*/      if ( !lat.trim().equals("") && !lng.trim().equals("") ) {         double hlat = double.parsedouble(lat.trim());         double hlong= double.parsedouble(lng.trim());          latlng dabaselocations =new latlng(hlat, hlong);          log.e("llaattaa", ""+hlat);         log.e("lloonngg", ""+hlong);           // show current location database locations            _googlemap.movecamera(cameraupdatefactory.newlatlng(dabaselocations));           _googlemap.addmarker(new            markeroptions().position(dabaselocations).title("start"));           } }  @override public void onproviderdisabled(string provider) {     // todo auto-generated method stub  }  @override public void onproviderenabled(string provider) {     // todo auto-generated method stub  }  @override public void onstatuschanged(string provider, int status, bundle extras) {     // todo auto-generated method stub  } @override protected void onresume() {     // todo auto-generated method stub     super.onresume();     serv=new gcmintentservice();     //serv.cancelnotification(getapplicationcontext());  }   } 

my logcat

03-06 13:03:40.187: e/androidruntime(18546): java.lang.runtimeexception: unable start activity  

logcat

    componentinfo{com.technowellservices.traffic/com.technowellservices.traffic.showmapactivity}:            java.lang.nullpointerexception         03-06 13:03:40.187: e/androidruntime(18546):    @         android.app.activitythread.performlaunchactivity(activitythread.java:1728)         03-06 13:03:40.187: e/androidruntime(18546):    @           android.app.activitythread.handlelaunchactivity(activitythread.java:1747)         03-06 13:03:40.187: e/androidruntime(18546):    @           android.app.activitythread.access$1500(activitythread.java:155)         03-06 13:03:40.187: e/androidruntime(18546):    @         android.app.activitythread$h.handlemessage(activitythread.java:993)     03-06 13:03:40.187: e/androidruntime(18546):    @     android.os.handler.dispatchmessage(handler.java:130)     03-06 13:03:40.187: e/androidruntime(18546):    @ android.os.looper.loop(sourcefile:351)     03-06 13:03:40.187: e/androidruntime(18546):    @        android.app.activitythread.main(activitythread.java:3814)     03-06 13:03:40.187: e/androidruntime(18546):    @        java.lang.reflect.method.invokenative(native method)     03-06 13:03:40.187: e/androidruntime(18546):    @ j     ava.lang.reflect.method.invoke(method.java:538)     03-06 13:03:40.187: e/androidruntime(18546):    @     com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:901)     03-06 13:03:40.187: e/androidruntime(18546):    @     com.android.internal.os.zygoteinit.main(zygoteinit.java:659)     03-06 13:03:40.187: e/androidruntime(18546):    @ dalvik.system.nativestart.main(native     method)     03-06 13:03:40.187: e/androidruntime(18546): caused by: java.lang.nullpointerexception     03-06 13:03:40.187: e/androidruntime(18546):    @      com.technowellservices.traffic.showmapactivity.oncreate(showmapactivity.java:66)     03-06 13:03:40.187: e/androidruntime(18546):    @      android.app.instrumentation.callactivityoncreate(instrumentation.java:1082)     03-06 13:03:40.187: e/androidruntime(18546):    @     android.app.activitythread.performlaunchactivity(activitythread.java:1692) 

you can't call this

 intent noticeintent = getintent(); 

before oncreate() method.

you should put in oncreate() method.

 @override  protected void oncreate(bundle savedinstancestate) {      super.oncreate(savedinstancestate);      setcontentview(r.layout.activity_show_map);      intent noticeintent = getintent();        // ...  } 

change from

  string message = noticeintent.getextras().getstring("message"); 

to

 string message = noticeintent.getstringextras("message"); 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -