查询流量信息

移动开发
根据选项选中运营商查询流量信息,调用系统发短信,系统查收到短信,自动将流量信息返回到页面上。

源码简介

 

根据选项选中运营商查询流量信息,调用系统发短信,系统查收到短信,自动将流量信息返回到页面上。
源码截图


源码片段:

  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("已使用"); 
  47.                     int wStart = body.lastIndexOf("MB"); 
  48.                     int wEnd = body.lastIndexOf("剩    余"); 
  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.     } 

源码下载:http://down.51cto.com/data/2015697

 

责任编辑:chenqingxiang 来源: 网络整理
相关推荐

2011-11-07 09:50:30

2011-06-13 16:20:25

网站信息架构收录流量

2009-08-03 16:27:17

2016-11-04 11:38:59

2022-10-17 00:00:00

SQLMySQL数据,

2017-01-23 10:10:09

2010-10-21 14:54:32

查询SQL Serve

2010-11-09 11:54:50

sql server查

2010-09-28 10:53:53

SQL表结构

2010-11-11 16:59:59

SQL Server视

2020-12-23 10:48:18

LinuxOSCPU

2023-10-29 16:14:07

2011-03-31 10:24:15

2010-05-19 11:07:12

Linux uptim

2010-10-29 11:22:23

Oracle用户会话

2022-09-27 19:40:09

查询流程信息

2019-11-28 09:04:32

DDoS网络攻击网络安全

2015-04-17 10:22:23

流量

2021-01-18 10:53:48

LinuxOSCPU

2015-11-10 10:57:18

流量不清零运营商
点赞
收藏

51CTO技术栈公众号