我记得cursorwindow中每条记录会分配一个空间,大小是2M,不知道是不是这个原因,
解决方案 »
- 导入现有Android工程时,出现Project has no default.properties file
- android关于格式化SD CARD 问题?
- strings.xml 中的内容访问方法
- android sqlite数据库无法打开
- android opengl 2d纹理的问题
- android 百度地图怎么获取不到GPS定位
- 求助:怎么样在Phonegap下,运行AngularJS的代码?
- 房产中的360度看图的演示是用什么技术做出来的?
- 如何设置application和activity的长宽为0
- 请问关于从网络数据库获取数据后,不能显示全部数据和换行的问题
- 导入第三方包的时候,eclipse提示Conversion to Dalvik format failed with error 1该怎么解决啊
- listview控件太多导致重回程序时异常
把下面这段放在 catch 和 finally 里。if(cursor!=null){
cursor.close();
cursor = null;
}
// TODO Auto-generated method stub
dbAdapter = new DatabaseAdapter(MonitoringService.this);
dbAdapter.open();
// try {
// Thread.sleep(5000);
// } catch (InterruptedException e) {}
// 截至启动机器
// 获取移动网络接收、发送数据总量,单位为byte,以下同上
mobileRx = TrafficStats.getMobileRxBytes();
mobileTx = TrafficStats.getMobileTxBytes(); // 获取全部网络接收、发送数据总量
totalRx = TrafficStats.getTotalRxBytes();
totalTx = TrafficStats.getTotalTxBytes();
// 计算WiFi网络接收、发送数据总量
wifiRx = totalRx - mobileRx;
wifiTx = totalTx - mobileTx;
if (mobileRx == -1 && mobileTx == -1) {
in.putExtra("mobileRx", "No");
in.putExtra("mobileTx", "No");
}
else {
mrx = (mobileRx - old_mobileRx); // 得到瞬时GPRS流量
old_mobileRx = mobileRx;
mtx = (mobileTx - old_mobileTx) ; // 得到瞬时GPRS流量
old_mobileTx = mobileTx; mrx = (long) ((float) (Math.round(mrx * 100.0)) / 100);
mtx = (long) ((float) (Math.round(mtx * 100.0)) / 100); in.putExtra("mobileRx", mrx / 1024 + "KB");
in.putExtra("mobileTx", mtx/ 1024 + "KB");
}
if (wifiRx == -1 && wifiTx == -1) {
in.putExtra("wifiRx", "No");
in.putExtra("wifiTx", "No");
} else {
wrx = (wifiRx - old_wifiRx); // 得到瞬时wifi流量
old_wifiRx = wifiRx;
wtx = (wifiTx - old_wifiTx); // 得到瞬时wifi流量
old_wifiTx = wifiTx;
wrx = (long) ((float) (Math.round(wrx * 100.0)) / 100);// 保留两位小数
wtx = (long) ((float) (Math.round(wtx * 100.0)) / 100);
in.putExtra("wifiRx", wrx / 1024 + "KB");
in.putExtra("wifiTx", wtx + "KB");
}
Date date = new Date() ;
mobileRx_all += mrx; // 求同一天的数据之和
mobileTx_all += mtx; // 求同一天的数据之和
wifiTx_all += wtx; // 求同一天的数据之和
wifiRx_all += wrx; // 求同一天的数据之和
if(count==12){
Cursor checkMobile = null;
try{
//如果存在该天GPRS流量的记录则跟新本条记录
if(mobileTx_all!=0||mobileRx_all!=0){
checkMobile = dbAdapter.check(1, date);//1 为 GPRS流量类型
if(checkMobile.moveToNext()){
long up = dbAdapter.getProFlowUp(1, date);
long dw = dbAdapter.getProFlowDw(1, date);
mobileTx_all += up ;
mobileRx_all += dw ;
dbAdapter.updateData(mobileTx_all, mobileRx_all, 1, date);
System.out.println("geng xin le GPRS liu liang sahngxing"+mobileTx_all+"xia xing"+mobileRx_all);
mobileTx_all=0;
mobileRx_all=0;
}
if(!checkMobile.moveToNext()){
dbAdapter.insertData(mobileTx_all, mobileRx_all, 1, date);
System.out.println("cun chu le GPRS liu liang sahngxing"+mobileTx_all+"xia xing"+mobileRx_all);
}
}
//如果数据库中没有今天的GPRS流量则插入一条信息
}catch(Exception e){
e.printStackTrace();
}finally{ checkMobile.close();
}
// TODO Auto-generated method stub
dbAdapter = new DatabaseAdapter(MonitoringService.this);
dbAdapter.open();
// try {
// Thread.sleep(5000);
// } catch (InterruptedException e) {}
// 截至启动机器
// 获取移动网络接收、发送数据总量,单位为byte,以下同上
mobileRx = TrafficStats.getMobileRxBytes();
mobileTx = TrafficStats.getMobileTxBytes(); // 获取全部网络接收、发送数据总量
totalRx = TrafficStats.getTotalRxBytes();
totalTx = TrafficStats.getTotalTxBytes();
// 计算WiFi网络接收、发送数据总量
wifiRx = totalRx - mobileRx;
wifiTx = totalTx - mobileTx;
if (mobileRx == -1 && mobileTx == -1) {
in.putExtra("mobileRx", "No");
in.putExtra("mobileTx", "No");
}
else {
mrx = (mobileRx - old_mobileRx); // 得到瞬时GPRS流量
old_mobileRx = mobileRx;
mtx = (mobileTx - old_mobileTx) ; // 得到瞬时GPRS流量
old_mobileTx = mobileTx; mrx = (long) ((float) (Math.round(mrx * 100.0)) / 100);
mtx = (long) ((float) (Math.round(mtx * 100.0)) / 100); in.putExtra("mobileRx", mrx / 1024 + "KB");
in.putExtra("mobileTx", mtx/ 1024 + "KB");
}
if (wifiRx == -1 && wifiTx == -1) {
in.putExtra("wifiRx", "No");
in.putExtra("wifiTx", "No");
} else {
wrx = (wifiRx - old_wifiRx); // 得到瞬时wifi流量
old_wifiRx = wifiRx;
wtx = (wifiTx - old_wifiTx); // 得到瞬时wifi流量
old_wifiTx = wifiTx;
wrx = (long) ((float) (Math.round(wrx * 100.0)) / 100);// 保留两位小数
wtx = (long) ((float) (Math.round(wtx * 100.0)) / 100);
in.putExtra("wifiRx", wrx / 1024 + "KB");
in.putExtra("wifiTx", wtx + "KB");
}
Date date = new Date() ;
mobileRx_all += mrx; // 求同一天的数据之和
mobileTx_all += mtx; // 求同一天的数据之和
wifiTx_all += wtx; // 求同一天的数据之和
wifiRx_all += wrx; // 求同一天的数据之和
if(count==12){
Cursor checkMobile = null;
try{
//如果存在该天GPRS流量的记录则跟新本条记录
if(mobileTx_all!=0||mobileRx_all!=0){
checkMobile = dbAdapter.check(1, date);//1 为 GPRS流量类型
if(checkMobile.moveToNext()){
long up = dbAdapter.getProFlowUp(1, date);
long dw = dbAdapter.getProFlowDw(1, date);
mobileTx_all += up ;
mobileRx_all += dw ;
dbAdapter.updateData(mobileTx_all, mobileRx_all, 1, date);
System.out.println("geng xin le GPRS liu liang sahngxing"+mobileTx_all+"xia xing"+mobileRx_all);
mobileTx_all=0;
mobileRx_all=0;
}
if(!checkMobile.moveToNext()){
dbAdapter.insertData(mobileTx_all, mobileRx_all, 1, date);
System.out.println("cun chu le GPRS liu liang sahngxing"+mobileTx_all+"xia xing"+mobileRx_all);
}
}
//如果数据库中没有今天的GPRS流量则插入一条信息
}catch(Exception e){
e.printStackTrace();
}finally{ checkMobile.close();
}