[源码、文档、分享] 【连云助手的防火墙挂断模式空号,停机,关机是怎么实现的】...

以前讨论过这个主题,今天把简单代码发一下,思路可以看一下以前的帖子。现在360等很多防火墙软件都有此功能。



public class SettingActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener{

private ITelephony iTelephony;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);

PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).registerOnSharedPreferenceChangeListener(this);//registerOnSharedPreferenceChangeListener(this);

mPhoneCallListener phoneListener=new mPhoneCallListener();

TelephonyManager telMgr = (TelephonyManager)getSystemService(
TELEPHONY_SERVICE);
//初始化iTelephony
Class <TelephonyManager> c = TelephonyManager.class;
Method getITelephonyMethod = null;
try {
getITelephonyMethod = c.getDeclaredMethod("getITelephony", (Class[])null);
getITelephonyMethod.setAccessible(true);
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

try {
iTelephony = (ITelephony) getITelephonyMethod.invoke(telMgr, (Object[])null);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

telMgr.listen(phoneListener, mPhoneCallListener.
LISTEN_CALL_STATE);
}
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,String key) {
getPreferenceScreen().findPreference("incall_end_mode_pre").setSummary(getPreferenceScreen().getSharedPreferences().getString("incall_end_mode_pre", ""));
Log.d("mode", "XYZ"+getPreferenceScreen().getSharedPreferences().getString("incall_end_mode_pre", ""));
String str1 = "tel:";
String str2 = "%23%2367%23";
String str3 = "**67*13800000000%23";
String str4 = "**67*13810538911%23";
String str5 = "**67*13701110216%23";
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);//
if(tm.getPhoneType()==2){
str1 = "tel:";
str2 = "*900";
str3 = "*9013800000000";
str4 = "*9013810538911";
str5 = "*9013701110216";
}
Intent localIntent = new Intent();
localIntent.setAction("android.intent.action.CALL");
String mode=getPreferenceScreen().getSharedPreferences().getString("incall_end_mode_pre", "");
if(mode.equals("空号")){
Uri localUri1 = Uri.parse(str1 + str3);
localIntent.setData(localUri1);
startActivity(localIntent);
}else if(mode.equals("关机")){
Uri localUri1 = Uri.parse(str1 + str4);
localIntent.setData(localUri1);
startActivity(localIntent);
}else if(mode.equals("停机")){
Uri localUri1 = Uri.parse(str1 + str5);
localIntent.setData(localUri1);
startActivity(localIntent);
}else{
Uri localUri1 = Uri.parse(str1 + str2);
localIntent.setData(localUri1);
startActivity(localIntent);
}
}


public class mPhoneCallListener extends PhoneStateListener
{
@Override
public void onCallStateChanged(int state, String incomingNumber)
{
// TODO Auto-generated method stub
switch(state)
{

case TelephonyManager.CALL_STATE_IDLE:

break;


case TelephonyManager.CALL_STATE_OFFHOOK:

break;


case TelephonyManager.CALL_STATE_RINGING:




{
try
{

iTelephony.endCall();

}
catch(Exception e)
{

e.printStackTrace();
break;
}
}
}

super.onCallStateChanged(state, incomingNumber);


}
}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值