源码介绍根据选项选择运营商查询路况信息,调用系统发送短信,系统收到短信后自动将路况信息返回页面。源代码截图源代码片段:@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_service);initView();initContentObserver();}privatevoidinitView(){yongde=(TextView)findViewById(R.id.yong);shengxia=(TextView)findViewById(R.id.wu);}privatevoidinitContentObserver(){mUri=Uri.parse("content://sms/");mContentResolver=this.getContentResolver();mContentResolver.registerContentObserver(mUri,true,newSMSContentObserver(newHandler()));}privateclassSMSContentObserverextendsContentObserver{publicSMSContentObserver(Handlerhandler){super(handler);}publicvoidonChange(booleanselfChange){super.onChange(selfChange);String[]projection=idString[]{"_","address","body","type","re??ad"};Stringwhere="address='10086'ANDread='0'";Cursorcursor=mContentResolver.query(mUri,projection,where,null,"约会sc");while(cursor.moveToNext()){Stringaddress=cursor.getString(cursor.getColumnIndex("address"));Stringbody=cursor.getString(cursor.getColumnIndex("body"));intid=cursor.getInt(cursor.getColumnIndex("_id"));Stringtype=cursor.getString(cursor.getColumnIndex("type"));System.out.println(body);if(body.length()>=10){intyStart=body.indexOf("MB");intyEnd=body.indexOf("已使用");intwStart=body.lastIndexOf("MB");intwEnd=body.lastIndexOf("剩余");Stringused=body.substring(yEnd,yStart);StringSurplus=body.substring(wEnd,wStart);yongde.setText(used+"MB");shengxia.setText(Surplus+"MB");System.out.println(used+Surplus);}}}}源码下载:http://down.51cto.com/data/2015697
