How to open a custom UI on incoming call with answer and reject button on it,I want to show custom UI instead of default dialer. I am using below code but dialer is open and my activity is not opened:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.callintruptdemo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".IncomingCall"></activity>
<receiver android:name=".CallReceiver">
<intent-filter >
<action android:name="android.intent.action.PHONE_STATE"></action>
</intent-filter>
</receiver>
</application>
I have a broadcast receiver which listen for incoming call and in receiver is:
@Override
public void onReceive(Context context, Intent intent) {
Log.d("CallReceiver","IncomingBroadcastReceiver: onReceive: ");
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
Log.d("CallReceiver","IncomingBroadcastReceiver: onReceive: " + state);
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING))
{
Intent i = new Intent(context, IncomingCall.class);
i.putExtras(intent);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
and code for IncomingCall class is:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
setContentView(R.layout.activity_main);
String number = getIntent().getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
TextView text = (TextView)findViewById(R.id.text);
text.setText("Incoming call from " + number);
}
but my custom UI is not displayed.
I also want button on my UI and how to receive a incoming call by click of that button. Thanks in advance.
edit:-- After updating my code I am able to open my custom UI, now I want to receive call by clicking a button on it. How to do this any help..