Get CellId and other Imformation from mobile phones via J2ME

阅读更多

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

 

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

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

你可能感兴趣的:(Mobile,BlackBerry,Nokia,Motorola,JavaME)