我希望禁用Android手机中的来电和去电功能。我的Android手机只允许运行GPRS和其他应用程序。
我的Android型号是三星Ace。
请提供关于此问题的解决方案。谢谢。
import java.lang.reflect.Method;
import android.content.Context;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import com.CallLogApp.helper.BlockNumberHelper;
import com.CallLogApp.util.UDF;
import com.android.internal.telephony.ITelephony;
public class CustomPhoneStateListener extends PhoneStateListener {
//private static final String TAG = "PhoneStateChanged";
Context context;
public CustomPhoneStateListener(Context context) {
super();
this.context = context;
}
@Override
public void onCallStateChanged(int state, String outGoingNumber) {
super.onCallStateChanged(state, outGoingNumber);
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
endCallIfBlocked(outGoingNumber);
break;
case TelephonyManager.CALL_STATE_RINGING:
break;
default:
break;
}
}
private void endCallIfBlocked(String outGoingNumber) {
try {
// Java reflection to gain access to TelephonyManager's
// ITelephony getter
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Class<?> c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
com.android.internal.telephony.ITelephony telephonyService = (ITelephony) m.invoke(tm);
if (new BlockNumberHelper(context).isBlocked(outGoingNumber))
{
telephonyService = (ITelephony) m.invoke(tm);
telephonyService.silenceRinger();
telephonyService.endCall();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
在电话接通并收到来电时,此处的CALL_STATE_OFFHOOK状态将被调用。
没有任何方法可以知道这是来电还是去电。
但是你可以在两种情况下结束即将接通的电话。
使用谷歌的Android API开发的任何内容...
都位于Android体系结构的应用程序层中。但是管理通话是在应用程序框架层中实现的。所以:
如果您想要阻止来自应用程序的电话呼叫,您无法避免电话呼叫状态的发生,因此一旦电话管理器处理了呼叫,请使用telephonyService.endCall()结束呼叫。
如果您真的需要避免电话呼叫到达您的应用程序层..我认为需要进行自定义Android编译。
但是您是否考虑过一些移动电信提供商提供“数据卡”,其中他们会阻止语音通道?这些是3G移动互联网调制解调器中的卡。