[源码、文档、分享] 【连云助手的防火墙挂断模式空号,停机,关机是怎么实现的】
来源:互联网 发布:淘宝网铁通固话充值 编辑:程序博客网 时间:2024/06/11 02:10
以前讨论过这个主题,今天把简单代码发一下,思路可以看一下以前的帖子。现在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);
}
}
}
- [源码、文档、分享] 【连云助手的防火墙挂断模式空号,停机,关机是怎么实现的】
- 实现防火墙的“电话已关机”,“此号码已停机”,“号码不存在”等提示音的方法
- STM8的停机模式
- rails网站分享到朋友圈功能是怎么实现的
- Handle通信具体到源码,是怎么实现的
- caffe源码——Euclidean Loss是怎么实现的
- Windows系统是怎么关机的?调试鱼与渔
- WIFI智能电源插座是怎么连上路由器的?
- MINA源码分析----怎么设置IP限制的(防火墙)
- 采用aidl技术实现电话的挂断
- 虚拟机是怎么实现的?
- mysql是怎么实现的
- TagHelper是怎么实现的
- 分享-struts2的AJAX怎么实现
- 停机问题的理解
- rocketmq的优雅停机
- 解决:在低电量关机的同时自动挂断电话电话
- mvc模式是怎么执行的???
- linux - basic operation
- ASP.NET实现数字和字符相混合的验证码
- 绝对正确!!教你如何配置ogre1.7.2+vs2010
- ORA-24324 & ORA-01041
- Android 下载一个文件以及打开这个apk文件
- [源码、文档、分享] 【连云助手的防火墙挂断模式空号,停机,关机是怎么实现的】
- 如何在ksh中重复执行上一个命令
- rz/sz安装
- 在C#程序中实现插件架构
- Rational license命令行使用-持续更新中
- ContentResolver
- 允许MySQL远程连接
- Oracle_SID与Instance_name的区别
- 在MyEclipse上面部署SmartFoxServer的运行环境