1

可能重复:
如何在 android 中拨打电话并在通话完成后返回我的活动?

我正在尝试在 Nexus-S 上的 Android 中使用以下代码 (Uri with Intent) 拨打/发起呼叫:

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

通话结束后在 Nexus-S 上显示设备通话记录屏幕,而不是返回我的活动。

通话结束后,设备本机通话记录屏幕是否不应该出现,并返回到我的活动或我想显示的其他活动?

4

1 回答 1

0

昨天我做了一个简单的应用程序,它拨打电话,结束通话后返回基本活动

这是我的代码可以帮助你

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;
                }    
            }
        }
    }   
}

主要的.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>

我的清单是

<?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>

让我知道是否还有任何问题。

于 2012-06-05T06:53:56.940 回答