Android在呼叫完成后显示设备呼叫日志屏幕/结束

时间:2012-06-05 05:29:31

标签: android calllog

  

可能重复:
  How to make a phone call in android and come back to my activity when the call is done?

我正试图在Nexus-S上的Android代码中使用(Uri with Intent)进行/启动呼叫:

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

在Nexus-S呼叫完成后,它显示设备呼叫日志屏幕,而不是返回我的活动。

在通话结束后,设备本机通话记录屏幕是否有任何显示方式,并返回我的活动或我想要显示的其他活动?

1 个答案:

答案 0 :(得分: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;
                }    
            }
        }
    }   
}

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>

,我的清单是

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

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