Issue
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.
Solution
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();
}
Answered By - umesh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.