您的位置:首页 > 理论基础 > 计算机网络

监听手机状态 网络,电话,位置等等~

2012-03-13 23:19 288 查看
mPhone = (TelephonyManager) this
.getSystemService(Context.TELEPHONY_SERVICE);
mPhone.listen(mPhoneStateListener,
PhoneStateListener.LISTEN_SERVICE_STATE
| PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
| PhoneStateListener.LISTEN_DATA_ACTIVITY);

mPhoneStateListener = new PhoneStateListener() {

@Override
public void onDataActivity(int direction) {
super.onDataActivity(direction);
Log.v("kevin", "onDataActivity: " + direction);
}

@Override
public void onDataConnectionStateChanged(int state) {
super.onDataConnectionStateChanged(state);
if(state == TelephonyManager.DATA_DISCONNECTED){
Log.v("kevin", "onDataConnectionStateChanged: " + state);
}
}

@Override
public void onServiceStateChanged(ServiceState serviceState) {
super.onServiceStateChanged(serviceState);
Log.v("kevin", "onServiceStateChanged");
}

};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐