2012-12-28 71 views
0

作出迴應我想停止啓動呼叫接收屏幕(默認情況下,如通常來電時)來電時發生。 而不是我想啓動我自己的活動來回應。停止發起呼叫接收屏幕,並通過自己的活動在android

任何人都可以請幫助我。 感謝

+0

轉到此鏈接拒絕來電:HTTP://計算器。 com/questions/10069667/how-to-call-an-activity-when-getting-incoming-call –

+0

這是一個很好的鏈接,但我的問題是我想停止默認的一個。 – umesh

+0

我用另一種解決方案解決了這個問題,並用我的理解發布了這個問題的答案。 – umesh

回答

1

先廣播接收器的子類
public class CallReceiver extends BroadcastReceiver {

在manifest.xml文件添加它
<receiver android:name="com.myapp.calldropper.CallReceiver" > <intent-filter> <action android:name="android.intent.action.PHONE_STATE" /> </intent-filter> </receiver>

中的onReceive

在默認

Intent callRejectIntent = new Intent(context, MainActivity.class); 
callRejectIntent.putExtra("MOBILE_NUMBER", mobNum); 
callRejectIntent.putExtra("REJECT_COUNT", rejectCount); 
callRejectIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
context.startActivity(callRejectIntent); 

再掀活動屏幕的活動將在默認的情況下啓動。現在您可以響應來自您的活動的接聽電話,您可以拒絕呼叫。
,因爲這會生成一個名爲com.android.internal.telephony的單獨包,並在此創建一個名爲ITelephony.aidl的簡單文本文件。該文件將包含以下

package com.android.internal.telephony; 
import android.os.Bundle; 
interface ITelephony { 
    boolean endCall(); 
    void dial(String number); 
    void answerRingingCall(); 
} 

中添加代碼的onCreate

TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); 
    try { 
     // "cheat" with Java reflection to gain access to TelephonyManager's ITelephony getter 
     Class<?> c = Class.forName(tm.getClass().getName()); 
     Method m = c.getDeclaredMethod("getITelephony"); 
     m.setAccessible(true); 
     telephonyService = (ITelephony) m.invoke(tm); 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

現在你可以通過調用以下功能

private void ignoreCall() { 
    try { 
     // telephonyService.silenceRinger(); 
     telephonyService.endCall(); 
    } catch (RemoteException e) { 
     e.printStackTrace(); 
    } 
    moveTaskToBack(true); 
    finish(); 
}