Android 测试工具类
2010-02-09 03:51:00 来源:WEB开发网这是Unlocking Android 这本书Sample的代码。直接上代码
package com.msi.manning.telephonyexplorer;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.telephony.gsm.GsmCellLocation;
import android.util.Log;
import android.widget.TextView;
public class TelephonyManagerExample extends Activity {
private TextView telMgrOutput;
@Override
public void onCreate(final Bundle icicle) {
Log.d(Constants.LOGTAG, "TelephonyManagerExample onCreate");
super.onCreate(icicle);
this.setContentView(R.layout.telmgrexample);
this.telMgrOutput = (TextView) this.findViewById(R.id.telmgroutput);
}
@Override
public void onStart() {
super.onStart();
// TelephonyManager
final TelephonyManager telMgr = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
this.telMgrOutput.setText(telMgr.toString());
// PhoneStateListener
PhoneStateListener phoneStateListener = new PhoneStateListener() {
@Override
public void onCallStateChanged(final int state, final String incomingNumber) {
TelephonyManagerExample.this.telMgrOutput
.setText(TelephonyManagerExample.this.getTelephonyOverview(telMgr));
Log.d(Constants.LOGTAG, "phoneState updated - incoming number - " + incomingNumber);
}
};
telMgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
String telephonyOverview = this.getTelephonyOverview(telMgr);
this.telMgrOutput.setText(telephonyOverview);
}
@Override
public void onPause() {
更多精彩
赞助商链接