2012-12-30 19 views
3

我正在開發應用程序,我想結束傳出調用。 這是主類在android中使用telephonyserivce.endcall結束調用()

import android.app.Activity; 
import android.content.ActivityNotFoundException; 
import android.content.Intent; 
import android.net.Uri; 
import android.os.Bundle; 
import android.util.Log; 

public class phonecalls extends Activity { 
/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    call(); 
} 

private void call() { 
try { 
    Intent callIntent = new Intent(Intent.ACTION_CALL); 
    callIntent.setData(Uri.parse("tel:123456789")); 
    startActivity(callIntent); 
} catch (ActivityNotFoundException activityException) { 
    Log.e("dialing-example", "Call failed", activityException); 
} 
} 
} 

和outgoingclass是這個

import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 
import android.os.Bundle; 
import android.telephony.TelephonyManager; 
import android.util.Log; 
import android.widget.Toast; 
import com.android.internal.telephony.ITelephony; 
import java.lang.reflect.Method; 

public class OutgoingCallReceiver extends BroadcastReceiver { 

private final String TAG = "CallControl"; 
Context context; 
String incomingNumber; 
ITelephony telephonyService; 

@Override 
    public void onReceive(Context context, Intent intent) { 
    TelephonyManager tm = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); 
    try { 
     // Java reflection to gain access to TelephonyManager's 
     // ITelephony getter 
     Bundle bundle = intent.getExtras(); 

     if(null == bundle) 
       return; 

     String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); 

     Log.i("OutgoingCallReceiver",phonenumber); 
     Log.i("OutgoingCallReceiver",bundle.toString()); 

     String info = "Detect Calls sample application\nOutgoing number: " + phonenumber; 


     Toast.makeText(context, info, Toast.LENGTH_LONG).show(); 

     Log.v(TAG, "Get getTeleService..."); 
     Class c = Class.forName(tm.getClass().getName()); 
     Method m = c.getDeclaredMethod("getITelephony"); 
     m.setAccessible(true); 
     telephonyService=(ITelephony) m.invoke(tm); 
     telephonyService.endCall(); 
    } catch (Exception e) { 
     e.printStackTrace(); 
     Log.e(TAG, 
       "FATAL ERROR: could not connect to telephony subsystem"); 
     Log.e(TAG, "Exception object: " + e); 
    }  

    } 
} 

但是,即使我能夠打印沒有呼叫沒有結束。當傳出呼叫開始時,表明廣播接收器正在工作。

任何建議

+0

終於完成了,所以任何人都需要幫助在這可以問..高興地幫助 –

+0

你能幫我嗎我需要一個工作版本結束來自特定號碼使用任何技術的呼叫。我需要一個2.3.3+設備上的工作版本,你能幫助我嗎? –

回答

0

是肯定存在雙向使用飛行模式或爲這個內部電話做到這一點無論是。我使用內部電話,我開發的代碼在這裏上傳https://github.com/deependersingla/end_calls

如果您還有什麼需要告訴我,我們很樂意爲您效勞。

+0

@ deepender Singla您上傳到您的github上的代碼確實可以阻止來電或去電呼叫您能否解釋它並且您是否也可以解釋在哪種格式下我們必須提供呼叫阻止號碼:如果我想要的號碼塊是0345xxxxxxx我應該只是通過它來達到這個目的,或者我輸入這樣的數字92345XXXXXXX你能解釋一下嗎? –

+0

這個項目不會阻塞任何數字,它只是在幾秒鐘後結束通話,它會給指定秒數的未接來電。 –

相關問題