1 publicclassmainactivityextendsappcompatactivity {2}
3 telephonymanagertelephonymanager; 4 myphonestatelistenermylistener; 5 @ override6public void oncreate (bundlesavedinstancestate )7super.oncreate ) savedinstancestate; 8 setcontentview (r.layout.activity _ main; 9 finaltextviewtextview1=(textview ) findviewbyid ) r.id.text1; 10 finaltextviewtextview2=(textview ) findviewbyid ) r.id.text2; 11ButtonButton=(Button ) findviewbyid(r.id.Button1); 12 telephony manager=(telephony manager ) main activity.this.getsystemservice (context.telephony _ service ); 13my listener=newmyphonestatelistener (; 14 button.setonclicklistener (new view.onclick listener () 15@override16publicvoidonclick ) viewv ) ) 17
18 string operator=telephony manager.getnetworkoperator (; 19/* *通过操作器输入MCC和MNC*/
20 int MCC=integer.parseint (operator.substring (0,3 ); 21 int MNC=integer.parseint (operator.substring (3); 22gsmcellocationlocation=(gsmcelllocation ) telephony manager.getcelllocation; 23/* *通过gsmcellocation与中国移动联通LAC和cellID*/
24 int lac=location.getLac (; 25 int cellid=location.getCid (; 26 system.out.print ln (' * ' MCC ' a ' MNC ' a ' lac ' a ' cellid ); 27 textView1.setText ('国家/地区编号: ' mcc '运营商编号: ' mnc 'LAC:' lac 'CellID:' cellid ); 28 list infos=telephony manager.getallcellinfo (; 29//list infos=telephony manager.getneighboringcellinfo ();
30字符串缓冲区sb=new字符串缓冲区(总数: ) infos.size ) ) (n ); 31for(Cellinfoinfo1:infos ) (/根据邻近地区总数为32 )/sb.append(lac: ) info1.getlac ) ); //当前邻区的lac33//sb.append(cid: ) info1.getcid ) ); //取出当前相邻区域的CID
34sb.append(cid: ) info1.tostring ) ); //目前邻区的cid35//sb.append(BSSS: ) (-1132*info1.getRSSI ) ) (((n ) ) ) ) ) ) ) ) ) ) )。
6637
38log.I(tag,"邻近基站信息: ) sb.tostring " ); 39 textview2. settext (sb.tostring () ); 40 }41 }; 42 telephony manager.listen (my listener,phonestatelistener.listen _ signal _ strengths ); 43//telephony manager.listen (cell listener,phonestatelistener.listen _ cell _ location ); //基站位置的变化
) 45 ) 45
46
47
48 privateclassmyphonestatelistenerextendsphonestatelistener 49 { 50/* getthesignalstrengthfromtheprovider,eachtiomethereisasare
51 @Override52
53 publicvoidonsignalstrengthschanged (54 super.onsignalstrengthschanged ) signal strength 56if=99 ) 57 toast.maketext (getapplicationcontext ),58 'Go to Firstdroid! gsmc INR=' string.value of (signal strength.getgsmsignalstrength (*2- 113 ),dbM )、Toast.LENGTH_SHORT ).show 552306;
60
1 system.out.println (' * * * ' string.value of (signal strength.getgsmsignalstrength ) * 2 - 113 ); 62 }63 }64 }