2011-03-26 60 views
0

工作,我必须使用下面的代码为来电拦截 How to reject incoming call programatically in android?
调用编程功能于Android的来电拦截代码没有在真实设备

它在模拟器,但不是真正的设备完全兼容,请给mw一些解决方案 是否需要谷歌的任何权限。 和telephonyService.endCall()也不起作用。

package com.android.MyCellFamily.DAReceiver; 
import java.lang.reflect.Method; 
import com.android.MyCellFamily.DAService.LocationService; 
import com.android.MyCellFamily.DB.ClsDataBaseUtils; 
import com.android.internal.telephony.ITelephony; 
import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 
import android.os.Bundle; 
import android.telephony.PhoneStateListener; 
import android.telephony.TelephonyManager; 
import android.util.Log; 
import android.widget.Toast; 

public class ClsIncomingCallBlocker_DAReceiver extends BroadcastReceiver { 
    ClsDataBaseUtils dts=new ClsDataBaseUtils(); 
    String clsincommingNumber; 

    @Override 
    public void onReceive(Context context, Intent intent) { 
     // TODO Auto-generated method stub 

     try 
     { 

      dts.createDatabse("MyCellFamily",context); 
      dts.createTable("tbl_Contacts", context); 
      dts.createBlockedStatusTable("tbl_BlockedContacts", context); 

      MyPhoneStateListener myPhoneStateListener = new MyPhoneStateListener(); 
      ((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)).listen(myPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); 
      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); 


      Bundle b = intent.getExtras(); 
      clsincommingNumber = b.getString(TelephonyManager.EXTRA_INCOMING_NUMBER); 
      Log.d("clsincommingNumber",clsincommingNumber); 
      if(dts.checkPreffContactsFrInCall("tbl_Contacts", clsincommingNumber).equals("true")) 
      { 
      //Answer Ringing Call 
      telephonyService.answerRingingCall(); 
      dts.close();  
      } 
      else if(dts.checkBlockedStatusFrInCall("tbl_BlockedContacts", clsincommingNumber).equals("true")) 
      { 
      System.out.println("Incoming blocker"+dts.checkBlockedStatusFrInCall("tbl_BlockedContacts", clsincommingNumber)); 
      //block incoming call 
      telephonyService.endCall(); 
      dts.close(); 
      } 
      else if(LocationService.getStatusOfDriving().equals("block")) 
      { 
      System.out.println("Your Status Of Driving is"+LocationService.getStatusOfDriving().toString()); 
      telephonyService.endCall(); 
      this.setResultData(null); 
      } 
      else 
      { 
      //Answer Ringing Call 
      telephonyService.answerRingingCall(); 
      dts.close(); 
      } 

     } 
     catch(Exception e) 
     { 

     } 
    } 
} 

回答

1

如果编程式呼叫阻塞或将永远由Android(或任何其他电话操作系统)正式支持,我将非常惊讶。你用来试图这样做的代码基本上是一个破解(它使用反射来获取和调用私有API方法,这是一个巧妙的技巧,但任何东西都很脆弱),并且不保证能够工作。

事实上,我完全希望Google在未来的Android更新中故意打破这些代码,如果它们还没有的话。他们所要做的就是重构getITelephony()somethingThatSoundsLessLikeAnObviousExploitPoint(),然后添加一个存根的方法,它什么都不做(或者让它离开,让应用程序处理异常或崩溃)。

因此,这个漏洞可能已经插入到您正在测试的设备上,即使它没有可能只是时间问题,未来的更新也会破坏每个使用此黑客的应用程序。您的开发时间可能会更好用于更新您的应用程序,以便尽可能优雅地处理被电话打断。

+0

是否有更好的方法来阻止呼叫,如果你有一个解决方案,请给我 – bindal 2011-03-26 12:18:40

+0

关于你的评论“(或任何其他电话操作系统)”。在Symbian上,可以回答并挂断第三方应用程序(Etel3rdParty)的来电,并通过Etel直接挂断电话(需要特殊权限 - 例如功能)。 – tidbeck 2011-10-07 09:45:07