【问题标题】:Android showing device Call-Log screen after call gets finished/End [duplicate]Android在通话完成/结束后显示设备通话记录屏幕[重复]
【发布时间】:2012-06-05 14:53:56
【问题描述】:

可能重复:
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 上显示设备通话记录屏幕,而不是返回我的活动。

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

【问题讨论】:

    标签: android calllog


    【解决方案1】:

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

    这是我的代码可以帮助你

    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>
    

    如果还有问题,请告诉我。

    【讨论】:

    • 感谢 RDC,您正在重新启动您的应用程序,但在我的情况下,我可以从应用程序的不同屏幕拨打电话,通话结束后,我需要在我拨打电话的屏幕上,使用以上我是否需要保持屏幕状态并再次启动/启动活动?
    猜你喜欢
    • 1970-01-01
    • 2020-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-15
    • 1970-01-01
    相关资源
    最近更新 更多