Reputation: 570
Hello I was wondering if there is a way to override the incoming call screen to add more functionality to it? If so could you either point me in the right direction or provide some sample code?
--------------------------------------------------EDIT: --------------------------
I got the receiver working well when the call comes in but how would I get the current window to override the call screen? This is what I got so far... but i get a classCastException trying to cast to activity from context, I cant think of any other way to gain access to the window.
@Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
if (extras != null) {
String state = extras.getString(TelephonyManager.EXTRA_STATE);
Log.w("DEBUG", state);
Log.w("DEBUG", "-------------------------------------------------- Broadcast Received");
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
String phoneNumber = extras
.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
Log.w("DEBUG", phoneNumber);
Activity activity = (Activity)context.getApplicationContext();
Window window = activity.getParent().getWindow();
window.addContentView(window.findViewById(R.layout.textalertbuttonview),null);
Log.w("DEBUG", "------------------------Button Added");
}
}
else {
Log.w("DEBUG", "---------------------------------------------------no Extras");
}
}
--------------------------------------------------EDIT 2: --------------------------
It doesn't seem after some research that I can actually add elements to the actual incoming call screen. So I will have to make my own view and override the incoming call screen. But I am still open for ideas... I saw incoming call plus but can not find the source code for that project.
Upvotes: 7
Views: 4741
Reputation: 10343
Generally speaking: You can set a BroadcastReceiver listening to PHONE_STATE:
<receiver android:name=".CallsBroadcastReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
Then inside this receiver (after checking the state of the phone you want to handle (ringing, in call, hanged up, etc.) you should get the current window (which should be the call screen) and add a view to it. And of course remove the view once the state is not the one you want to handle.
Very general, but that's the idea.
Upvotes: 2