2012-12-28 40 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(); 
}