1

Possible Duplicate:
How to make a phone call in android and come back to my activity when the call is done?

I am trying to make/initiate call using (Uri with Intent) following code in Android on Nexus-S:

 Intent callIntent = new Intent(Intent.ACTION_CALL);
 callIntent.setData(Uri.parse("tel:"+phoneNo));
 startActivity(callIntent);

On Nexus-S after call gets finished it is showing Device Call Logs screen instead of going back to my activity.

Is there any way that device native call logs screen should not appear after call ends, and return back to my activity or some other activity which I would like to show?

Community
  • 1
  • 1
Aparna
  • 119
  • 1
  • 10

1 Answers1

0

yesterday i made a simple app , it makes call and after ending the call come back to Base Activity

here is my code may help you

MakePhoneCallActivity.java

package com.rdc;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MakePhoneCallActivity extends Activity { 
    private Button button; 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main); 
        button = (Button) findViewById(R.id.buttonCall); 
        // add button listener
        button.setOnClickListener(new OnClickListener() { 
            @Override
            public void onClick(View arg0) {

                Intent callIntent = new Intent(Intent.ACTION_CALL);
                callIntent.setData(Uri.parse("tel:9741817902"));
                startActivity(callIntent); 
            } 
        });         
        // add PhoneStateListener
        PhoneCallListener phoneListener = new PhoneCallListener();
        TelephonyManager telephonyManager = (TelephonyManager) this
                    .getSystemService(Context.TELEPHONY_SERVICE);
        telephonyManager.listen(phoneListener,
                PhoneStateListener.LISTEN_CALL_STATE);
    }

    //monitor phone call activities
    private class PhoneCallListener extends PhoneStateListener {     
        private boolean isPhoneCalling = false;  
        String TAG = "DEBUG";    
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {

            if (TelephonyManager.CALL_STATE_RINGING == state) {
                    // phone ringing
                Log.i(TAG, "RINGING, number: " + incomingNumber);
            }    
            if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
                    // active
                Log.i(TAG, "OFFHOOK");   
                isPhoneCalling = true;
            }    
            if (TelephonyManager.CALL_STATE_IDLE == state) {
                // run when class initial and phone call ended, 
                // need detect flag from CALL_STATE_OFFHOOK
                Log.i(TAG, "IDLE");  
                if (isPhoneCalling) {

                    Log.i(TAG, "restart app");   
                    // restart app
                    Intent i = getBaseContext().getPackageManager()
                        .getLaunchIntentForPackage(
                            getBaseContext().getPackageName());
                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(i);    
                    isPhoneCalling = false;
                }    
            }
        }
    }   
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/buttonCall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Make a call" />

</LinearLayout>

and my manifest is

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.rdc"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />

    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".MakePhoneCallActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

let me know if still any trouble is there.

swiftBoy
  • 35,607
  • 26
  • 136
  • 135
  • Thanks RDC, Here you are restarting your application, but in my case I could make call from my application's different screen and after call ends I need to be at my screen from where I have made call, with above Do I need to maintain screen states and launch/start activity where I was again? – Aparna Jun 11 '12 at 10:43