android如何防止手机误拨号号如何挂掉

Android开发中如何实现自动挂断***的代码-安卓教程-手机开发-壹聚教程网Android开发中如何实现自动挂断***的代码
android的新版本已经把Phone类给隐藏起来了,本文我们来分享两个自动挂***的java实现方法,想实现这个功能又不知如何下手的朋友可以参考一下。
实现方法一代码1、准备AIDL文件挂断***的AIDL文件都是Android自带的文件,我们可以从Android的源代码中找到这两个文件,它们分别是NeighboringCellInfo.aidl和ITelephony.aidl我把NeighboringCellInfo.aidl放在项目的android.telephony包下,将ITelephony.aidl放在com.android.internal.telephony包下NeighboringCellInfo.aid具体内容如下:/*&//device/java/android/android/content/Intent.aidl&
**&Copyright&2007,&The&Android&Open&Source&Project&
**&Licensed&under&the&Apache&License,&Version&2.0&(the&&License&);&
**&you&may¬&use&this&file&except&in&compliance&with&the&License.&
**&You&may&obtain&a©&of&the&License&at&
**&&&&&http://www.apache.org/licenses/LICENSE-2.0&
**&Unless&required&by&applicable&law&or&agreed&to&in&writing,&software&
**&distributed&under&the&License&is&distributed&on&an&&AS&IS&&BASIS,&
**&WITHOUT&WARRANTIES&OR&CONDITIONS&OF&ANY&KIND,&either&express&or&implied.&
**&See&the&License&for&the&specific&language&governing&permissions&and&
**&limitations&under&the&License.&
package&android.&&
parcelable&NeighboringCellIITelephony.aidl具体内容如下:/*&
&*&Copyright&(C)&2007&The&Android&Open&Source&Project&
&*&Licensed&under&the&Apache&License,&Version&2.0&(the&&License&);&
&*&you&may¬&use&this&file&except&in&compliance&with&the&License.&
&*&You&may&obtain&a©&of&the&License&at&
&*&&&&&&http://www.apache.org/licenses/LICENSE-2.0&
&*&Unless&required&by&applicable&law&or&agreed&to&in&writing,&software&
&*&distributed&under&the&License&is&distributed&on&an&&AS&IS&&BASIS,&
&*&WITHOUT&WARRANTIES&OR&CONDITIONS&OF&ANY&KIND,&either&express&or&implied.&
&*&See&the&License&for&the&specific&language&governing&permissions&and&
&*&limitations&under&the&License.&
package&com.android.internal.&&
import&android.os.B&&
import&java.util.L&&
import&android.telephony.NeighboringCellI&&
&*&Interface&used&to&interact&with&the&phone.&&Mostly&this&is&used&by&the&
&*&TelephonyManager&class.&&A&few&places&are&still&using&this&directly.&
&*&Please&clean&them&up&if&possible&and&use&TelephonyManager&insteadl.&
&*&{@hide}&
interface&ITelephony&{&&
&&&&&*&Dial&a&number.&This&doesn't&place&the&call.&It&displays&
&&&&&*&the&Dialer&screen.&
&&&&&*&@param&number&the&number&to&be&dialed.&If&null,&this&
&&&&&*&would&display&the&Dialer&screen&with&no&number&pre-filled.&
&&&&void&dial(String&number);&&
&&&&&*&Place&a&call&to&the&specified&number.&
&&&&&*&@param&number&the&number&to&be&called.&
&&&&void&call(String&number);&&
&&&&&*&If&there&is¤tly&a&call&in&progress,&show&the&call&screen.&
&&&&&*&The&DTMF&dialpad&may&or&may¬&be&visible&initially,&depending&on&
&&&&&*&whether&it&was&up&when&the&user&last&exited&the&InCallScreen.&
&&&&&*&@return&true&if&the&call&screen&was&shown.&
&&&&boolean&showCallScreen();&&
&&&&&*&Variation&of&showCallScreen()&that&also&specifies&whether&the&
&&&&&*&DTMF&dialpad&should&be&initially&visible&when&the&InCallScreen&
&&&&&*&comes&up.&
&&&&&*&@param&showDialpad&if&true,&make&the&dialpad&visible&initially,&
&&&&&*&&&&&&&&&&&&&&&&&&&&otherwise&hide&the&dialpad&initially.&
&&&&&*&@return&true&if&the&call&screen&was&shown.&
&&&&&*&@see&showCallScreen&
&&&&boolean&showCallScreenWithDialpad(boolean&showDialpad);&&
&&&&&*&End&call&or&go&to&the&Home&screen&
&&&&&*&@return&whether&it&hung&up&
&&&&boolean&endCall();&&
&&&&&*&Answer&the¤tly-ringing&call.&
&&&&&*&If&there's&already&a¤t&active&call,&that&call&will&be&
&&&&&*&automatically&put&on&hold.&&If&both&lines&are¤tly&in&use,&the&
&&&&&*¤t&active&call&will&be&ended.&
&&&&&*&TODO:&provide&a&flag&to&let&the&caller&specify&what&policy&to&use&
&&&&&*&if&both&lines&are&in&use.&&(The¤t&behavior&is&hardwired&to&
&&&&&*&&answer&incoming,&end&ongoing&,&which&is&how&the&CALL&button&
&&&&&*&is&specced&to&behave.)&
&&&&&*&TODO:&this&should&be&a&oneway&call&(especially&since&it's&called&
&&&&&*&directly&from&the&key&queue&thread).&
&&&&void&answerRingingCall();&&
&&&&&*&Silence&the&ringer&if&an&incoming&call&is¤tly&ringing.&
&&&&&*&(If&vibrating,&stop&the&vibrator&also.)&
&&&&&*&It's&safe&to&call&this&if&the&ringer&has&already&been&silenced,&or&
&&&&&*&even&if&there's&no&incoming&call.&&(If&so,&this&method&will&do¬hing.)&
&&&&&*&TODO:&this&should&be&a&oneway&call&too&(see&above).&
&&&&&*&&&&&&&(Actually&*all*&the&methods&here&that&return&void&can&
&&&&&*&&&&&&&probably&be&oneway.)&
&&&&void&silenceRinger();&&
&&&&&*&Check&if&we&are&in&either&an&active&or&holding&call&
&&&&&*&@return&true&if&the&phone&state&is&OFFHOOK.&
&&&&boolean&isOffhook();&&
&&&&&*&Check&if&an&incoming&phone&call&is&ringing&or&call&waiting.&
&&&&&*&@return&true&if&the&phone&state&is&RINGING.&
&&&&boolean&isRinging();&&
&&&&&*&Check&if&the&phone&is&idle.&
&&&&&*&@return&true&if&the&phone&state&is&IDLE.&
&&&&boolean&isIdle();&&
&&&&&*&Check&to&see&if&the&radio&is&on&or¬.&
&&&&&*&@return&returns&true&if&the&radio&is&on.&
&&&&boolean&isRadioOn();&&
&&&&&*&Check&if&the&SIM&pin&lock&is&enabled.&
&&&&&*&@return&true&if&the&SIM&pin&lock&is&enabled.&
&&&&boolean&isSimPinEnabled();&&
&&&&&*&Cancels&the&missed&calls¬ification.&
&&&&void&cancelMissedCallsNotification();&&
&&&&&*&Supply&a&pin&to&unlock&the&SIM.&&Blocks&until&a&result&is&determined.&
&&&&&*&@param&pin&The&pin&to&check.&
&&&&&*&@return&whether&the&operation&was&a&success.&
&&&&boolean&supplyPin(String&pin);&&
&&&&&*&Handles&PIN&MMI&commands&(PIN/PIN2/PUK/PUK2),&which&are&initiated&
&&&&&*&without&SEND&(so&&code&dial&/code&&is¬&appropriate).&
&&&&&*&@param&dialString&the&MMI&command&to&be&executed.&
&&&&&*&@return&true&if&MMI&command&is&executed.&
&&&&boolean&handlePinMmi(String&dialString);&&
&&&&&*&Toggles&the&radio&on&or&off.&
&&&&void&toggleRadioOnOff();&&
&&&&&*&Set&the&radio&to&on&or&off&
&&&&boolean&setRadio(boolean&turnOn);&&
&&&&&*&Request&to&update&location&information&in&service&state&
&&&&void&updateServiceLocation();&&
&&&&&*&Enable&location&update¬ifications.&
&&&&void&enableLocationUpdates();&&
&&&&&*&Disable&location&update¬ifications.&
&&&&void&disableLocationUpdates();&&
&&&&&*&Enable&a&specific&APN&type.&
&&&&int&enableApnType(String&type);&&
&&&&&*&Disable&a&specific&APN&type.&
&&&&int&disableApnType(String&type);&&
&&&&&*&Allow&mobile&data&connections.&
&&&&boolean&enableDataConnectivity();&&
&&&&&*&Disallow&mobile&data&connections.&
&&&&boolean&disableDataConnectivity();&&
&&&&&*&Report&whether&data&connectivity&is&possible.&
&&&&boolean&isDataConnectivityPossible();&&
&&&&Bundle&getCellLocation();&&
&&&&&*&Returns&the&neighboring&cell&information&of&the&device.&
&&&&List&NeighboringCellInfo&&getNeighboringCellInfo();&&
&&&&&int&getCallState();&&
&&&&&int&getDataActivity();&&
&&&&&int&getDataState();&&
&&&&&*&Returns&the¤t&active&phone&type&as&integer.&
&&&&&*&Returns&TelephonyManager.PHONE_TYPE_CDMA&if&RILConstants.CDMA_PHONE&
&&&&&*&and&TelephonyManager.PHONE_TYPE_GSM&if&RILConstants.GSM_PHONE&
&&&&int&getActivePhoneType();&&
&&&&&*&Returns&the&CDMA&ERI&icon&index&to&display&
&&&&int&getCdmaEriIconIndex();&&
&&&&&*&Returns&the&CDMA&ERI&icon&mode,&
&&&&&*&0&-&ON&
&&&&&*&1&-&FLASHING&
&&&&int&getCdmaEriIconMode();&&
&&&&&*&Returns&the&CDMA&ERI&text,&
&&&&String&getCdmaEriText();&&
&&&&&*&Returns&true&if&CDMA&provisioning&needs&to&run.&
&&&&boolean&getCdmaNeedsProvisioning();&&
&&&&&&*&Returns&the&unread&count&of&voicemails&
&&&&&&*/&&
&&&&int&getVoiceMessageCount();&&
&&&&&&*&Returns&the&network&type&
&&&&&&*/&&
&&&&int&getNetworkType();&&
&&&&&*&Return&true&if&an&ICC&card&is&present&
&&&&boolean&hasIccCard();&&
}准备好文件后,会在项目的gen目录下自动生成与两个文件所在包一样的包,同时会自动生成ITelephony.java文件如下图:2、新建PhoneUtils类,并写一个方法endCall()这个方法就是挂断***的方法,具体实现如下//挂断***&&
public&void&endCall(String&incomingNumber){&&
&&&&try&{&&
&&&&&&&&&&&&Class&?&&clazz&=&Class.forName(&android.os.ServiceManager&);&&
&&&&&&&&&&&&Method&method&=&clazz.getMethod(&getService&,&String.class);&&
&&&&&&&&&&&&IBinder&ibinder&=&(IBinder)&method.invoke(null,&Context.TELEPHONY_SERVICE);&&
&&&&&&&&&&&&ITelephony&iTelephony&=&ITelephony.Stub.asInterface(ibinder);&&
&&&&&&&&&&&&iTelephony.endCall();&&
&&&&&&&&}(Exception&e){&&
&&&&&&&&&&&&e.printStrackTrace();&&
&&&&&&&&}&&
}3、注册权限最后别忘了在AndroidManifest.xml文件中注册权限具体实现如下:&uses-permission&android:name=&android.permission.CALL_PHONE&/&实现方法二代码Android自动挂断***android的新版本已经把Phone类给隐藏起来了,想要用代码实现挂断***,就必须通过AIDL才行,第一步:在程序中新建一个包,包名必须为:com.android.internal.telephony,因为要使用aidl,第二步:在这个包里面新建一个名为ITelephony.aidl的文件,然后在文件里面写入代码:package&com.android.internal.
interface&ITelephony{
boolean&endCall();
void&answerRingingCall();
}然后保存,eclie会自动在gen文件夹下生成一个ITelephony.java的类。主程序的代码如下:package&ling.P
import&java.lang.reflect.M
import&android.app.A
import&android.os.B
import&android.os.RemoteE
import&android.telephony.PhoneStateL
import&android.telephony.TelephonyM
import&com.android.internal.telephony.IT
public&class&Phonemanager&extends&Activity&{
&&&&/**&Called&when&the&activity&is&first&created.&*/
&&&&private&ITelephony&&iT
&&&&private&TelephonyManager&
&&&&public&void&onCreate(Bundle&savedInstanceState)&{
&&&&&&&&super.onCreate(savedInstanceState);
&&&&&&&&setContentView(R.layout.main);
&&&&&&&&phoner();
&&&&&&&&manager.listen(new&PhoneStateListener(){
&&&@Override
&&&public&void&onCallStateChanged(int&state,&String&incomingNumber)&{
&&&&//&TODO&Auto-generated&method&stub
&&&&super.onCallStateChanged(state,&incomingNumber);
&&&&switch(state){
&&&&//判断是否有***接入
&&&&case&1:
&&&&&try&{
&&&&&&//当***接入时,自动挂断。
&&&&&&iTelephony.endCall();
&&&&&&System.out.println(&uncall&);
&&&&&}&catch&(RemoteException&e)&{
&&&&&&//&TODO&Auto-generated&catch&block
&&&&&&e.printStackTrace();
&&&&&&&&},&PhoneStateListener.LISTEN_CALL_STATE);
&&&&public&void&phoner(){
&&&&&manager&=&(TelephonyManager)getSystemService(TELEPHONY_SERVICE);
&&&&&&&&Class&&TelephonyManager&&c&=&TelephonyManager.&
&&&&&&&&&Method&getITelephonyMethod&=&&
&&&&&&&&&try&{&
&&&&&&&&&&&&&&&&getITelephonyMethod&=&c.getDeclaredMethod(&getITelephony&,&(Class[])null);&
&&&&&&&&&&&&&&&&getITelephonyMethod.setAccessible(true);&
&&&&&&&&&&iTelephony&=&(ITelephony)&getITelephonyMethod.invoke(manager,&(Object[])null);&
&&&&&&&&&}&catch&(IllegalArgumentException&e)&{&
&&&&&&&&&&&&&&&e.printStackTrace();&
&&&&&&&&&}&catch&(Exception&e)&{&
&&&&&&&&&&&&&&e.printStackTrace();&
&&&&&&&&&}
}只要在***接入时,再加上一个判断***号码是否是黑名单的功能,就可以做成一个黑名单的程序了,获取***号码的函数是:getLine1Number();
上一页: &&&&&下一页:相关内容Android开发之黑名单来电自动挂断
本实例允许用户动态添加号码到黑名单,并实现黑名单来电自动挂断。程序通过创建PhoneStateListener***器来***TelephonyManager的通话状态来实现该功能。
由于自 10之后Android不再对外公开挂断***的API,如果需要挂断***必须使用AIDL与***管理Service进行通信,并调用服务中的API实现结束***。
为了调用远程的AIDL Service,开发者需要将Android中的如下两个文拷到指定位置:
com.android.internal.telephony包下的ITelephony.aidl
android.telephony包下的NeighboringCellInfo.aidl
vcD4KPHA+1eLR+b7Nu+HU2mdlbs7EvP680M/Cyfqzyc/g06a1xC5KYXZhzsS8/qGjPC9wPgo8cD7B7c3itffTw0FQSbXEt723qMjnufvT0LK7veK1xLXYt72/ydLUss6/vKO6Q2xhc3MuZm9yTmFtZSgptcTX99PD0+vKudPD19y94TwvcD4KPHA+we3N4rG+yrXA/cq508NCYXNlQWRhcHRlctf3zqpMaXN0Vmlld7XEysrF5Mb3o6xCYXNlQWRhcHRlcr7f09C63Me/tcS2qNbG0M2hozwvcD4KPHA+0d3Kvs28xqyjujwvcD4KPGhyPgo8cD48aW1nIHNyYz0="/uploadfile/Collfiles/55.gif" alt="\">
程序代码:
package com.jph.
import java.lang.reflect.M
import java.util.ArrayL
import com.android.internal.telephony.IT
import android.os.B
import android.os.IB
import android.provider.ContactsC
import android.telephony.PhoneStateL
import android.telephony.TelephonyM
import android.view.V
import android.view.ViewG
import android.view.View.OnClickL
import android.widget.BaseA
import android.widget.B
import android.widget.CheckB
import android.widget.ListV
import android.app.A
import android.app.AlertD
import android.content.DialogI
import android.database.C
* Describe:
* 黑名单自动挂断
* 本实例实现了获取联系人,并将选中的联系人添加到黑名单中
* 并通过ITelephony.aidl与NeighboringCellInfo.aidl
* 接口使用AIDL与***管理Servic进行通信挂断黑名单中的***
* @author jph
public class CallGuard extends Activity {
Button btnM
TelephonyManager tM
//创建一个集合用于保存黑名单中的号码
ArrayListblockList=new ArrayList();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnManage=(Button)findViewById(R.id.btnManage);
tManager=(TelephonyManager) getSystemService(TELEPHONY_SERVICE);
//创建***状态***器
PhoneStateListener pStateListener=new PhoneStateListener(){
public void onCallStateChanged(int state, String incomingNumber) {
// TODO Auto-generated method stub
switch (state) {
case TelephonyManager.CALL_STATE_IDLE://空闲状态不做处理
case TelephonyManager.CALL_STATE_OFFHOOK://接起***不做处理
case TelephonyManager.CALL_STATE_RINGING://正在响铃
//如果来电号码在黑名单中则自动挂断
if (isBlock(incomingNumber)) {
//获取android.os.ServiceManager类的对象的getService()方法
Method method=Class.forName("android.os.ServiceManager").
getMethod("getService",String.class);
// 获取远程TELEPHONY_SERVICE的IBinder对象的代理
IBinder binder =(IBinder)method.invoke(null, new Object[] {TELEPHONY_SERVICE});
// 将IBinder对象的代理转换为ITelephony对象
ITelephony telephony=ITelephony.Stub.asInterface(binder);
//挂断***
telephony.endCall();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
super.onCallStateChanged(state, incomingNumber);
//为TelephonyManager添加***器
tManager.listen(pStateListener, PhoneStateListener.LISTEN_CALL_STATE);
btnManage.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
//查询通信录中的***号码
final Cursor cursor=getContentResolver().query(
monDataKinds.Phone.CONTENT_URI,
null, null, null, null);
//创建一个BaseAdapter作为ListView的适配器
BaseAdapter adapter=new BaseAdapter() {
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
//将游标的指针移动到指定位置
cursor.moveToPosition(position);
CheckBox box=new CheckBox(CallGuard.this);
//获取指定位置的***号码
String number=cursor.getString(cursor.getColumnIndex(
monDataKinds.Phone.NUMBER));
//去掉***号码中间的中划线、空格
number.replace("-", "").replace(" ", "");
box.setText(number);
//如果该号码已经被加入黑名单、默认勾选该号码
if (isBlock(number)) {
box.setChecked(true);
public long getItemId(int position) {
// TODO Auto-generated method stub
public Object getItem(int position) {
// TODO Auto-generated method stub
//返回列表的总条数
public int getCount() {
// TODO Auto-generated method stub
return cursor.getCount();
//加载line布局文件
View view=getLayoutInflater().inflate(R.layout.line, null);
//获取line布局文件中Id为list的
final ListView list=(ListView)view.findViewById(R.id.list);
list.setAdapter(adapter);
new AlertDialog.Builder(CallGuard.this).setView(view).setPositiveButton("确定",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
blockList.clear();
for (int i = 0; i < list.getCount(); i++) {
CheckBox box=(CheckBox)list.getChildAt(i);
//如果联系人被选中则将其添加到blockList集合
if (box.isChecked()) {
blockList.add(box.getText().toString());
}).show();
private boolean isBlock(String number) {
// TODO Auto-generated method stub
//判断号码是否在blockList集合中
for (String s:blockList) {
if (s.equals(number)) {
最后别忘添加相应的权限:
AndroidManifest.xml
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467142',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'Android挂断、接听***
一个很简陋的小例子
参考自:通过AIDL及反射机制,使用隐藏API挂断***
个人理解上其实是同名类跨进程欺骗Dalvik VM,大伙儿可进一步联想扩展下功能,定会有惊喜!!!
以下为,仅做个人备份及参考。
package lab.sodino. import android.app.A import android.os.B public class PhoneCall extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }
package lab.sodino. import android.app.S import android.content.BroadcastR import android.content.C import android.content.I import android.telephony.TelephonyM import android.widget.T /** *@author Sodino Email:sodinoopen@hotmail&br/& *@version
下午10:38:55 */ public class PhoneListener extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); LogOut.out(this, &ord:& + isOrderedBroadcast() + & act:& + action); Toast toast = Toast.makeText(context, &&, Toast.LENGTH_SHORT); if (action.equals(&android.intent.action.NEW_OUTGOING_CALL&)) { toast.setText(&Outgoing&); } else { toast.setText(&InComing&); TelephonyManager tm = (TelephonyManager) context .getSystemService(Service.TELEPHONY_SERVICE); boolean incomingFlag = String incoming_number = &&; switch (tm.getCallState()) { case TelephonyManager.CALL_STATE_RINGING: incomingFlag =// 标识当前是来电incoming_number = intent.getStringExtra(&incoming_number&); LogOut.out(this, &RINGING :& + incoming_number); try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } Intent tmpI = new Intent(context, ShowAct.class); tmpI.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(tmpI); case TelephonyManager.CALL_STATE_OFFHOOK: if (incomingFlag) { LogOut.out(this, &incoming ACCEPT :& + incoming_number); } case TelephonyManager.CALL_STATE_IDLE: if (incomingFlag) { LogOut.out(this, &incoming IDLE&); } } } toast.show(); } }
package lab.sodino. import java.lang.reflect.M import android.app.A import android.content.C import android.os.B import android.telephony.TelephonyM import android.view.V import android.widget.B import com.android.internal.telephony.IT /** *@author Sodino Email:sodinoopen@hotmail&br/& *@version
下午08:33:25 */ public class ShowAct extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setWindowAnimations(0); setContentView(R.layout.show); Button btnRefuse = (Button) findViewById(R.id.btnRefuse); btnRefuse.setOnClickListener(new Button.OnClickListener() { public void onClick(View view) { endCall(); } }); Button btnReceiver = (Button) findViewById(R.id.btnRefuse); btnReceiver.setOnClickListener(new Button.OnClickListener() { public void onClick(View view) { answerCall(); } }); } private void answerCall() { TelephonyManager telMag = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); Class&TelephonyManager& c = TelephonyManager. Method mthEndCall = try { mthEndCall = c.getDeclaredMethod(&getITelephony&, (Class[]) null); mthEndCall.setAccessible(true); ITelephony iTel = (ITelephony) mthEndCall.invoke(telMag, (Object[]) null); iTel.answerRingingCall(); LogOut.out(this, iTel.toString()); } catch (Exception e) { e.printStackTrace(); } LogOut.out(this, &answer call&); } private void endCall() { TelephonyManager telMag = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); Class&TelephonyManager& c = TelephonyManager. Method mthEndCall = try { mthEndCall = c.getDeclaredMethod(&getITelephony&, (Class[]) null); mthEndCall.setAccessible(true); ITelephony iTel = (ITelephony) mthEndCall.invoke(telMag, (Object[]) null); iTel.endCall(); LogOut.out(this, iTel.toString()); } catch (Exception e) { e.printStackTrace(); } LogOut.out(this, &endCall test&); } public void onStart() { super.onStart(); // 1.经测试,貌似无法杀掉phone程序// ActivityManager actMag = (ActivityManager) // getSystemService(Context.ACTIVITY_SERVICE); // actMag.killBackgroundProcesses(&com.android.phone&); // 2.来个恶搞:直接回桌面去,heihei... // Intent tmpI = new Intent(Intent.ACTION_MAIN); // tmpI.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // tmpI.addCategory(Intent.CATEGORY_HOME); // startActivity(tmpI); // LogOut.out(this, &killBgPro&&startHome&); } public void onPause() { super.onPause(); finish(); } }
package com.android.internal. interface ITelephony{ boolean endCall(); void answerRingingCall(); }
&?xml version=&1.0& encoding=&utf-8&?& &manifest xmlns:android=&/apk/res/android& package=&lab.sodino.phonecall& android:versionCode=&1& android:versionName=&1.0&& &application android:icon=&@drawable/icon& android:label=&@string/app_name&& &activity android:name=&.PhoneCall& android:label=&@string/app_name&& &intent-filter& &action android:name=&android.intent.action.MAIN& /& &category android:name=&android.intent.category.LAUNCHER& /& &/intent-filter& &/activity& &activity android:name=&.ShowAct& android:launchMode=&singleInstance&& &/activity& &receiver android:name=&.PhoneListener&& &intent-filter android:priority=&-1000&& &action android:name=&android.intent.action.PHONE_STATE&&&/action& &category android:name=&android.intent.category.DEFAULT&&&/category& &/intent-filter& &intent-filter& &action android:name=&android.intent.action.NEW_OUTGOING_CALL&&&/action& &category android:name=&android.intent.category.DEFAULT&&&/category& &/intent-filter& &/receiver& &/application& &uses-sdk android:minSdkVersion=&3& /& &uses-permission android:name=&android.permission.MODIFY_PHONE_STATE&&&/uses-permission& &uses-permission android:name=&android.permission.CALL_PHONE&&&/uses-permission& &uses-permission android:name=&android.permission.READ_PHONE_STATE&&&/uses-permission& &/manifest&
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467142',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'

参考资料

 

随机推荐