David
David

Reputation: 21

Launch an activity at end of a phone call on Android

I would like to launch an activity at the end of a phone call. Could not find any reference to that. How can I do it?

Upvotes: 2

Views: 1425

Answers (2)

Givi
Givi

Reputation: 3283

You do not have to use a service. You could register a Receiver in the AndroidManifest.xml file like that:

<receiver android:name=".callerID.IncomingCallReceiver" >
            <intent-filter android:priority="0">
                <action android:name="android.intent.action.PHONE_STATE" />
            </intent-filter>
        </receiver>

In you Java class check the phone state and launch your desired activity - DON'T forget to launch it with FLAG_ACTIVITY_NEW_TASK.

Upvotes: 0

broschb
broschb

Reputation: 5006

I haven't tried this, but I would assume you could have some service running(always on in background), that utilizes the PhoneStateListener. You could then listen for LISTEN_CALL_STATE which says it "Listen for changes to the device call state". I would assume this would fire when a call starts, stops, etc. You could then launch your activity from the service when you receive a message that a call ended.

Note you would probably have to track the states, and no when you are in CALL_STATE_OFFHOOK and go to CALL_STATE_IDLE that the call ended.

Upvotes: 2

Related Questions