Get CellId and other Imformation from mobile phones via J2ME

 

Without GPS or Network Operator we can still use the Location Based Service, via the help of CellId(Cell ID the location of Cell Identities of GSM-networks). Google has one enormous database of cell ids which are linked to a longitude and latitude position, that why Google Map client know where you are even you have no embedded GPS--it is not open. But there are other opened cellid DBs that we can use freely: opencellid , mobiforge.com and http://realtimeblog.free.fr/
Ok, one we can get the cell from phone we can query the location from these cellid DB. In GSM networks, all cells in the world have a globally unique ID made up of four numbers:
cell ID, LAC, MNC, and MCC.

For example, for Motorola:
Using JavaME to obtain Cell Positioning information

  1. {
  2. ….
  3. String cellid = System.getProperty("CellID");
  4. String lac = System.getProperty("LocAreaCode");
  5. String imsi = System.getProperty("IMSI");
  6. // Example IMSI (O2 UK): 234103530089555
  7. String mcc = imsi.substring(0,3); // 234 (UK)
  8. String mnc = imsi.substring(3,5); // 10 (O2)
  9. String location = mcc + mnc + lac + cellID; // A globally unique ID for a cell
  10. }

Information from Truly Mobile JavaME Applications: Location, Media Capture, and Connectivity

But get Cellid is still limited by mobile phone platform, Sign-certificate and Operator:

Nokia
s40 3rd Fp1 edition, requers operator or manufactureer signing
S60 3rd edition, FP2(released 2008 and newer, does not work on e.g. N95),no singing required

SonyEricsson:
Java platform 7.3 or higher (released around 2006 and newer)
older phone may need firmware update (7.1->7.3)
does not work in SE symbian (ie. UIQ) or windownsmobile(Xperia X1) phone
Information from Terminal-based Mobile Positioning overview

And notice, even you use the right code and sign your application, it is still not possible to query the cellID, because some telecom-operators have limited this service.

The fowllowing J2ME code could help you, J2ME Polish Syntax is used here to make the procedure easier. The functions here is not complete, because some manufactories have not released their J2ME API documents to query the cellID. If you have some information which is not included in the codes please let me and others know, please supplement here, thx!

  1. /**
  2. * get the cell id in the phone
  3. *
  4. * @return
  5. */
  6. public static String getCellId(){
  7. String out = "";
  8. try{
  9.  
  10. out = System.getProperty("Cell-ID");
  11. if(out== null || out.equals("null") || out.equals(""))
  12. out = System.getProperty("CellID");
  13. if(out== null ||out.equals("null")|| out.equals(""))
  14. System.getProperty("phone.cid");
  15. //#if polish.Vendor == Nokia
  16. if(out== null ||out.equals("null")|| out.equals(""))
  17. out = System.getProperty("com.nokia.mid.cellid");
  18. //#elif polish.Vendor == Sony-Ericsson
  19. if(out== null ||out.equals("null")|| out.equals(""))
  20. out = System.getProperty("com.sonyericsson.net.cellid");
  21. //#elif polish.Vendor == Motorola
  22. if(out== null ||out.equals("null")|| out.equals(""))
  23. out = System.getProperty("phone.cid");//System.getProperty("CellID");
  24. //#elif polish.Vendor == Samsung
  25. if(out== null ||out.equals("null")|| out.equals(""))
  26. out = System.getProperty("com.samsung.cellid");
  27. //#elif polish.Vendor == Siemens
  28. if(out== null ||out.equals("null")|| out.equals(""))
  29. out = System.getProperty("com.siemens.cellid");
  30. //#elif polish.Vendor == BlackBerry
  31. if(out== null ||out.equals("null")|| out.equals(""))
  32. //#= out = GPRSInfo.getCellInfo().getCellId();
  33. //#else
  34. if(out== null ||out.equals("null")|| out.equals(""))
  35. out = System.getProperty("cid");
  36. //#endif
  37.  
  38. }catch(Exception e){
  39. return out==null?"":out;
  40. }
  41.  
  42. return out==null?"":out;
  43. }
  44.  
  45. /**
  46. * get the lac sring from phone
  47. */
  48. public static String getLAC(){
  49. String out = "";
  50. try{
  51.  
  52. out = System.getProperty("phone.lac");
  53.  
  54. //#if polish.Vendor == Nokia
  55. if(out== null ||out.equals("null")|| out.equals(""))
  56. out = System.getProperty("com.nokia.mid.lac");
  57. //#elif polish.Vendor == Sony-Ericsson
  58. if(out== null ||out.equals("null")|| out.equals(""))
  59. out = System.getProperty("com.sonyericsson.net.lac");
  60. //#elif polish.Vendor == Motorola
  61. if(out== null ||out.equals("null")|| out.equals(""))
  62. out = System.getProperty("LocAreaCode");
  63. //#elif polish.Vendor == Samsung
  64. if(out== null ||out.equals("null")|| out.equals(""))
  65. out = System.getProperty("com.samsung.cellid");
  66. //#elif polish.Vendor == Siemens
  67. if(out== null ||out.equals("null")|| out.equals(""))
  68. out = System.getProperty("com.siemens.cellid");
  69. //#elif polish.Vendor == BlackBerry
  70. if(out== null ||out.equals("null")|| out.equals(""))
  71. //#= out = GPRSInfo.getCellInfo().getLAC();
  72. //#else
  73. if(out== null ||out.equals("null")|| out.equals(""))
  74. out = System.getProperty("cid");
  75. //#endif
  76.  
  77. }catch(Exception e){
  78. return out==null?"":out;
  79. }
  80.  
  81. return out==null?"":out;
  82. }
  83.  
  84. /**
  85. * Example IMSI (O2 UK): 234103530089555
  86. String mcc = imsi.substring(0,3); // 234 (UK)
  87. String mnc = imsi.substring(3,5); // 10 (O2)
  88. * @return
  89. */
  90. public static String getIMSI(){
  91. String out = "";
  92. try{
  93.  
  94. out = System.getProperty("IMSI");
  95. if(out== null ||out.equals("null")|| out.equals(""))
  96. out = System.getProperty("phone.imsi") ;
  97. //#if polish.Vendor == Nokia
  98. if(out== null ||out.equals("null")|| out.equals(""))
  99. out = System.getProperty("com.nokia.mid.mobinfo.IMSI");
  100. if(out== null ||out.equals("null")|| out.equals(""))
  101. out = System.getProperty("com.nokia.mid.imsi");
  102. //#elif polish.Vendor == Sony-Ericsson
  103. /* if(out== null ||out.equals("null")|| out.equals(""))
  104. out = System.getProperty("com.sonyericsson.imsi");*/
  105. //#elif polish.Vendor == Motorola
  106. if(out== null ||out.equals("null")|| out.equals(""))
  107. out = System.getProperty("IMSI");
  108. //#elif polish.Vendor == Samsung
  109. /* if(out== null ||out.equals("null")|| out.equals(""))
  110. out = System.getProperty("com.samsung.imei");*/
  111. //#elif polish.Vendor == Siemens
  112. /* if(out== null ||out.equals("null")|| out.equals(""))
  113. out = System.getProperty("com.siemens.imei");*/
  114. //#elif polish.Vendor == BlackBerry
  115. if(out== null ||out.equals("null")|| out.equals(""))
  116. //#= out = GPRSInfo.getCellInfo().getBSIC();
  117. //#else
  118. if(out== null ||out.equals("null")|| out.equals(""))
  119. out = System.getProperty("imsi");
  120. //#endif
  121.  
  122. }catch(Exception e){
  123. return out==null?"":out;
  124. }
  125.  
  126. return out==null?"":out;
  127. }
  128.  
  129. /**
  130. *
  131. * For moto, Example IMSI (O2 UK): 234103530089555
  132. String mcc = imsi.substring(0,3); // 234 (UK)
  133. * @return
  134. */
  135. public static String getMCC(){
  136. String out = "";
  137. try{
  138.  
  139. if(out== null ||out.equals("null")|| out.equals(""))
  140. out = System.getProperty("phone.mcc") ;
  141. //#if polish.Vendor == Nokia
  142. if(out== null ||out.equals("null")|| out.equals(""))
  143. //out = System.getProperty("com.nokia.mid.mobinfo.IMSI");
  144. //#elif polish.Vendor == Sony-Ericsson
  145. if(out== null ||out.equals("null")|| out.equals(""))
  146. out = System.getProperty("com.sonyericsson.net.mcc");
  147. //#elif polish.Vendor == Motorola
  148. if(out== null ||out.equals("null")|| out.equals("")){
  149. out = getIMSI().equals("")?"": getIMSI().substring(0,3);
  150. }
  151. //#elif polish.Vendor == Samsung
  152. /* if(out== null ||out.equals("null")|| out.equals(""))
  153. out = System.getProperty("com.samsung.imei");*/
  154. //#elif polish.Vendor == Siemens
  155. /* if(out== null ||out.equals("null")|| out.equals(""))
  156. out = System.getProperty("com.siemens.imei");*/
  157. //#elif polish.Vendor == BlackBerry
  158. if(out== null ||out.equals("null")|| out.equals(""))//getMNC()
  159. //#= out = GPRSInfo.getCellInfo().getMCC();
  160. //#else
  161. if(out== null ||out.equals("null")|| out.equals(""))
  162. out = System.getProperty("mcc");
  163. //#endif
  164.  
  165. }catch(Exception e){
  166. return out==null?"":out;
  167. }
  168.  
  169. return out==null?"":out;
  170. }
  171.  
  172. /**
  173. *
  174. * For moto, Example IMSI (O2 UK): 234103530089555
  175. String mnc = imsi.substring(3,5); // 10 (O2)
  176. * @return
  177. */
  178. public static String getMNC(){
  179. String out = "";
  180. try{
  181.  
  182. if(out== null ||out.equals("null")|| out.equals(""))
  183. out = System.getProperty("phone.mnc") ;
  184. //#if polish.Vendor == Nokia
  185. if(out== null ||out.equals("null")|| out.equals(""))
  186. out = getIMSI().equals("")?"": getIMSI().substring(3,5);
  187. //#elif polish.Vendor == Sony-Ericsson
  188. if(out== null ||out.equals("null")|| out.equals(""))
  189. out = System.getProperty("com.sonyericsson.net.mnc");
  190. //#elif polish.Vendor == Motorola
  191. if(out== null ||out.equals("null")|| out.equals("")){
  192. out = getIMSI().equals("")?"": getIMSI().substring(3,5);
  193. }
  194. //#elif polish.Vendor == Samsung
  195. /* if(out== null ||out.equals("null")|| out.equals(""))
  196. out = System.getProperty("com.samsung.imei");*/
  197. //#elif polish.Vendor == Siemens
  198. /* if(out== null ||out.equals("null")|| out.equals(""))
  199. out = System.getProperty("com.siemens.imei");*/
  200. //#elif polish.Vendor == BlackBerry
  201. if(out== null ||out.equals("null")|| out.equals(""))//getMNC()
  202. //#= out = GPRSInfo.getCellInfo().getMCC();
  203. //#else
  204. if(out== null ||out.equals("null")|| out.equals(""))
  205. out = System.getProperty("mnc");
  206. //#endif
  207.  
  208. }catch(Exception e){
  209. return out==null?"":out;
  210. }
  211.  
  212. return out==null?"":out;
  213. }
  214.  
  215. /**
  216. * not used now
  217. * get the IMEI (International Mobile Equipment Identity (IMEI)) in the phone
  218. *
  219. * @return
  220. */
  221. public static String getIMEI(){
  222. String out = "";
  223. try{
  224.  
  225. out = System.getProperty("com.imei");
  226. //#if polish.Vendor == Nokia
  227. if(out== null ||out.equals("null")|| out.equals(""))
  228. out = System.getProperty("phone.imei");
  229. if(out== null ||out.equals("null")|| out.equals(""))
  230. out = System.getProperty("com.nokia.IMEI");
  231. if(out== null ||out.equals("null")|| out.equals(""))
  232. out = System.getProperty("com.nokia.mid.imei");
  233. if(out== null ||out.equals("null")|| out.equals(""))
  234. out = System.getProperty("com.nokia.mid.imei");
  235. //#elif polish.Vendor == Sony-Ericsson
  236. if(out== null ||out.equals("null")|| out.equals(""))
  237. out = System.getProperty("com.sonyericsson.imei");
  238. //#elif polish.Vendor == Motorola
  239. if(out== null ||out.equals("null")|| out.equals(""))
  240. out = System.getProperty("IMEI");
  241. if(out== null ||out.equals("null")|| out.equals(""))
  242. out = System.getProperty("com.motorola.IMEI");
  243. //#elif polish.Vendor == Samsung
  244. if(out== null ||out.equals("null")|| out.equals(""))
  245. out = System.getProperty("com.samsung.imei");
  246. //#elif polish.Vendor == Siemens
  247. if(out== null ||out.equals("null")|| out.equals(""))
  248. out = System.getProperty("com.siemens.imei");
  249. //#else
  250. if(out== null ||out.equals("null")|| out.equals(""))
  251. out = System.getProperty("imei");
  252. //#endif
  253.  
  254. }catch(Exception e){
  255. return out==null?"":out;
  256. }
  257.  
  258. return out==null?"":out;
  259. }

Some J2ME applications are also available:
http://www.ottaky.com/midlets.php#netmon2
http://www.cellspotting.com/webpages/cellspotting.html

Ref:
http://en.wikipedia.org/wiki/GSM_localization
http://www.paxmodept.com/telesto/blogitem.htm?id=531
http://www.slideshare.net/jaakl/terminalbased-mobile-positioning-overview-presentation
http://www.ottaky.com/midlets.php#netmon2
http://www.cellspotting.com/webpages/cellspotting.html

原文出处:http://www.easywms.com/easywms/?q=zh-hant/node/3589

 

posted @ 2009-10-22 00:57  Sunny Peng  阅读(1980)  评论(0编辑  收藏  举报