2024年3月29日发(作者:)
Android实现自动接听和挂掉电话源代码
添加权限
<?xml version="1.0" encoding="utf-8"?>
androidrientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> android:layout_width="fill_parent" android:id="@+id/rGrpSelect"> android:layout_width="fill_parent" android:id="@+id/rbtnAutoAccept" android:text="所有来电自动接听"> android:layout_width="fill_parent" android:id="@+id/rbtnAutoReject" android:text="所有来电自动挂断"> android:layout_width="fill_parent" android:id="@+id/tbtnRadioSwitch" android:textOn="Radio已经启动" android:textOff="Radio已经关闭" android:textSize="24dip" android:textStyle="normal"> android:layout_width="fill_parent" android:id="@+id/tbtnDataConn" android:textSize="24dip" android:textStyle="normal" android:textOn="允许数据连接" android:textOff="禁止数据连接">
是手机功能类,从TelephonyManager中实例化ITelephony并返回,源码
如下:
package lephony;
import ;
import ;
import hony;
import onyManager;
import ;
public class PhoneUtils {
/**
* 从TelephonyManager中实例化ITelephony,并返回
*/
static public ITelephony getITelephony(TelephonyManager telMgr) throws Exception {
Method getITelephonyMethod = ss().getDeclaredMethod("getITelephony");
essible(true);//私有化函数也能使用
return (ITelephony)(telMgr);
}
static public void printAllInform(Class clsShow) {
try {
// 取得所有方法
Method[] hideMethod = laredMethods();
int i = 0;
for (; i < ; i++) {
Log.e("method name", e());
}
// 取得所有常量
Field[] allFields = lds();
for (i = 0; i < ; i++) {
Log.e("Field name", e());
}
} catch (SecurityException e) {
// throw new RuntimeException(sage());
tackTrace();
} catch (IllegalArgumentException e) {
// throw new RuntimeException(sage());
tackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
tackTrace();
}
}
}
来电操作
是主类,使用PhoneStateListener监听通话状态,以及实现上述4种
电话控制功能,源码如下:
package lephony;
import ty;
import ;
import tateListener;
import onyManager;
import ;
import ;
import roup;
import Button;
public class testTelephony extends Activity {
/** Called when the activity is first created. */
RadioGroup rg;//来电操作单选框


发布评论