Start a short video when an incoming call is detected, first case using the emulator.
Posted
by Emanuel
on Stack Overflow
See other posts from Stack Overflow
or by Emanuel
Published on 2010-05-14T21:33:15Z
Indexed on
2010/05/14
23:04 UTC
Read the original article
Hit count: 403
I want to be able to start a short video on an incoming phone call. The video will loop until the call is answered. I've loaded the video onto the emulator sdcard then created the appropriate level avd with a path to the sdcard.iso file on disk. Since I'm running on a Mac OS x snow leopard I am able to confirm the contents of the sdcard. All testing has be done on the Android emulator.
In a separate project TestVideo I created an activity that just launches the video from the sdcard. That works as expected. Then I created another project TestIncoming that creates an activity that creates a PhoneStateListener that overrides the onCallStateChanged(int state, String incomingNumber) method. In the onCallStateChanged() method I check if state == TelephonyManager.CALL_STATE_RINGING. If true I create an Intent that starts the video. I'm actually using the code from the TestVideo project above. Here is the code snippet.
PhoneStateListener callStateListener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if(state == TelelphonyManager.CALL_STATE_RINGING) {
Intent launchVideo = new Intent(MyActivity.this, LaunchVideo.class);
startActivity(launchVideo);
}
}
};
The PhoneStateListener is added to the TelephonyManager.listen() method like so,
telephonyManager.listen(callStateListener, PhoneStateListener.LISTEN_CALL_STATE);
Here is the part I'm unclear on, the manifest. What I've tried is the following:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.incomingdemo"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".IncomingVideoDemo"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.ANSWER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".LaunchVideo"
android:label="LaunchVideo">
</activity>
</application>
<uses-sdk android:minSdkVersion="2" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
</manifest>
I've run the debugger after setting breakpoints in the IncomingVideoDemo activity where the PhoneStateListener is created and none of the breakpoints are hit. Any insights into solving this problem is greatly appreciated. Thanks.
© Stack Overflow or respective owner