原文 http://www.3geye.net/?3/viewspace-3137
这个例子实在是简单的很,一个编辑器,加上一个确定就可以打电话了。
公布代码吧。
package com.gggeye.android;
import android.app.Activity;
import android.os.Bundle;
import android.os.DeadObjectException;
import android.os.IServiceManager;
import android.os.ServiceManagerNative;
import android.telephony.IPhone;
import android.view.Menu;
import android.widget.EditText;
public class PhoneCellDemo extends Activity {
android.widget.EditText edit;
String localPhoneNumber;
String operatorISOCountry;
String operatorName;
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
localPhoneNumber = android.os.SystemProperties
.get(android.telephony.TelephonyProperties.PROPERTY_LINE1_NUMBER);
operatorISOCountry = android.os.SystemProperties
.get(android.telephony.TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY);
operatorName = android.os.SystemProperties
.get(android.telephony.TelephonyProperties.PROPERTY_OPERATOR_ALPHA);
;
Logger.info("localPhoneNumber = > " + localPhoneNumber);
Logger.info("operatorISOCountry = > " + operatorISOCountry);
Logger.info("operatorISOCountry = > " + operatorName);
edit = new EditText(this);
this.setContentView(edit);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, 0, "打电话");
//
return true;
}
// @Override
// public boolean onPrepareOptionsMenu(Menu menu){
// super.onPrepareOptionsMenu(menu);
// return true;
// }
@Override
public boolean onOptionsItemSelected(Menu.Item item){
switch (item.getId()) {
case 0:
this.cellPhone(this.edit.getText().toString());
return true;
}
return false;
}
private void cellPhone(String Number){
try {
IPhone iPhone = getPhoneInterface();
iPhone.call(Number);
} catch (DeadObjectException e) {
Logger.error(e);
}
}
private static IPhone getPhoneInterface() throws DeadObjectException {
IServiceManager sm = ServiceManagerNative.getDefault();
IPhone phoneService = IPhone.Stub.asInterface(sm.getService("phone"));
return phoneService;
}
}
代码就这么简单,慢慢看吧。