0

I want to stop launching of call receive screen (default, as usual when call comes) when any incoming call occurs. Instead of that I want to launch my own Activity to respond.

halfer
  • 19,824
  • 17
  • 99
  • 186
umesh
  • 1,148
  • 1
  • 12
  • 25
  • Go with this link: http://stackoverflow.com/questions/10069667/how-to-call-an-activity-when-getting-incoming-call – Ricky Khatri Dec 28 '12 at 06:33
  • it was a good link, but my problem is i want to stop default one. – umesh Dec 28 '12 at 06:59
  • i got resolved this problem with an alternative solution and posting the answer for this question with my understanding. – umesh Jan 02 '13 at 12:19

1 Answers1

1

first make a subclass of BroadcastReceiver
public class CallReceiver extends BroadcastReceiver {

add it in manifest.xml file
<receiver android:name="com.myapp.calldropper.CallReceiver" > <intent-filter> <action android:name="android.intent.action.PHONE_STATE" /> </intent-filter> </receiver>

in onReceive start another Activity Screen upon the default

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);  

your Activity will launch upon the default one. now you can responde the incomming call from your activity, you can Reject call.
for that make a seperate package named com.android.internal.telephony and in this create a simple text file named ITelephony.aidl. this file will contain

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

add code below in 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();
    }  

now you can reject the call by calling below function

private void ignoreCall() {
    try {
        // telephonyService.silenceRinger();
        telephonyService.endCall();
    } catch (RemoteException e) {
        e.printStackTrace();
    }
    moveTaskToBack(true);
    finish();
}
umesh
  • 1,148
  • 1
  • 12
  • 25