how to get cell tower location in android -
i want find nearest cell tower location. tried
private class servicestatehandler extends handler { public void handlemessage(message msg) { switch (msg.what) { case my_notification_id: servicestate state = mphonestatereceiver.getservicestate(); system.out.println(state.getcid()); system.out.println(state.getlac()); system.out.println(mphonestatereceiver.getsignalstrength()); break; } } }
i tried link not working me how find user location using cell tower?
i think doing wrong. because link answer working other person did same code shown in link using 2,2 google api create project not able cell tower location
the code have doesn't wait intent in activity oncreate fetches reference telephony service , when displaying calls getcelllocation() when required.
m_manager = (telephonymanager)getsystemservice(context.telephony_service); gsmcelllocation loc = (gsmcelllocation)m_manager.getcelllocation(); if (loc != null) { out.format("location "); if (loc.getcid() == -1) { out.format("cid: unknown "); } else { out.format("cid: %08x ", loc.getcid()); } if (loc.getlac() == -1) { out.format("lac: unknown\n"); } else { out.format("lac: %08x\n", loc.getlac()); } }
when listening phonestateservice intents though see have call listen
on telephonymanager , specify fields of interest. in case was:
@override public int onstartcommand(intent intent, int flags, int startid) { log.d(tag, "service start"); m_manager.listen(m_listener, phonestatelistener.listen_signal_strengths | phonestatelistener.listen_service_state | phonestatelistener.listen_call_state); return super.onstartcommand(intent, flags, startid); }
you need add listen_cell_location
list.
note: did add access_coarse_location permission app manifest? noted in phonestatelistener documentation, fields empty if not have permission information.
Comments
Post a Comment