呼叫后设备断开连接

时间:2013-10-28 20:27:01

标签: android broadcastreceiver

我正在尝试编写一个捕获语音呼叫的简单广播接收器。下面是我的接收器类和清单文件。每次我尝试运行它时,我的虚拟设备在通话后立即断开连接。我做错了什么???

package com.example.example06;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class MyPhoneReceiver extends BroadcastReceiver {
    public void onReceive(Context context, Intent intent) {
        Toast.makeText(context, "A phone call was received!", Toast.LENGTH_LONG).show();
    }
}

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.example06"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <receiver 
            android:name="MyPhoneReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.PHONE_STATE" ></action>
            </intent-filter>            
        </receiver>                
    </application>

</manifest>

1 个答案:

答案 0 :(得分:0)

也许将清单改为:

            <receiver
              android:name="com.example.android.blah.MyPhoneReceiver"
              android:exported="false" >
               <intent-filter>
                 <action android:name="android.intent.action.PHONE_STATE" ></action>
               </intent-filter>
           </receiver>