2011-03-26 27 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