Query traffic information

Query traffic information

Source code introduction

Select the operator according to the options to query the traffic information, call the system to send text messages, the system checks the received text messages and automatically returns the traffic information to the page.
Source code screenshot


Source code snippet:

  1. @Override  
  2. protected   void onCreate(Bundle savedInstanceState) {
  3. super .onCreate(savedInstanceState);
  4. setContentView(R.layout.activity_service);
  5. initView();
  6. initContentObserver();
  7. }
  8.   
  9. private   void initView() {
  10. yongde = (TextView) findViewById(R.id.yong);
  11. shengxia = (TextView) findViewById(R.id.wu);
  12. }
  13.   
  14. private   void initContentObserver() {
  15. mUri = Uri.parse( "content://sms/" );
  16. mContentResolver = this .getContentResolver();
  17. mContentResolver.registerContentObserver(mUri, true ,
  18. new SMSContentObserver( new Handler()));
  19. }
  20.   
  21. private   class SMSContentObserver extends ContentObserver {
  22. public SMSContentObserver(Handler handler) {
  23. super (handler);
  24. }
  25.   
  26. public   void onChange( boolean selfChange) {
  27. super .onChange(selfChange);
  28.               
  29. String[] projection = new String[] { "_id" , "address" , "body" ,
  30. "type" , "read" };
  31.               
  32. String where = " address = '10086' AND read = '0'" ;
  33. Cursor cursor = mContentResolver.query(mUri, projection, where,
  34. null , "date desc" );
  35.               
  36. while (cursor.moveToNext()) {
  37. String address = cursor.getString(cursor
  38. .getColumnIndex( "address" ));
  39. String body = cursor.getString(cursor.getColumnIndex( "body" ));
  40. int id = cursor.getInt(cursor.getColumnIndex( "_id" ));
  41. String type = cursor.getString(cursor.getColumnIndex( "type" ));
  42.   
  43. System.out.println(body);
  44. if (body.length() >= 10 ) {
  45. int yStart = body.indexOf( "MB" );
  46. int yEnd = body.indexOf( "used" );
  47. int wStart = body.lastIndexOf( "MB" );
  48. int wEnd = body.lastIndexOf( "remaining" );
  49. String used = body.substring(yEnd,yStart);
  50. String Surplus = body.substring( wEnd,wStart);
  51. yongde.setText(used + " MB" );
  52. shengxia.setText(Surplus + " MB" );
  53. System.out.println(used + Surplus);
  54.   
  55. }
  56. }
  57. }
  58. }

Source code download: http://download..com/data/2015697

<<:  Hello, this is Xiaomi Department Store

>>:  Mobile Assistant

Recommend

Real gems or "fake gems"? Talk about "gemstone improvement"...

Gem lovers all hope to buy a genuine, authentic a...

How to write promotional ideas, write like this!

Why does my ad not have any traffic even though i...

How does operations perform data analysis? 3 ideas and 8 methods!

I've been reading "Chief Growth Officer&...

TV games can also be played like this. LeTV game console brings arcade pleasure

Speaking of fighting games, if you tell me that y...

The way to fine-tune APP operations: "users + push" based on data

There are too many apps to choose from on the mar...

If you are nearsighted, you won’t have presbyopia? Don’t be naive!

Author: Yan Xin, resident physician at Beijing To...

Why are the hottest days during the "dog days" instead of the summer solstice?

We are lucky to live on the paradise of life - th...

Cultural Relics + 928 Sets! World-class Major Archaeological Discovery →

About 150 kilometers southeast of Sanya City, Hai...

Google: Future Android phones will receive 4 years of software updates

On December 17, according to XDA reports, Google ...

Methodology! How operators can take advantage of hot topics to plan events!

The operations department plans activities based ...

Besides painkillers, what other methods can we use to relieve pain?

Produced by: Science Popularization China Author:...

A comprehensive guide to App promotion and operation knowledge: [Data Analysis]

Part 1 How to evaluate channel quality from data ...