0

http://developer.android.com/reference/android/provider/VoicemailContract.html

我不知道如何用 VOICEMAIL 制作广播接收器。当您收到语音邮件时,您会在通知中看到“NEW VOICEMAIL”,图标就像磁带一样。

这是我的代码:

AndroidManifest.xml

<receiver android:name=".VoiceBrocast" >
        <intent-filter>
            <action android:name="android.intent.action.NEW_VOICEMAIL" />
        </intent-filter>
 </receiver>

<uses-permission android:name="com.android.voicemail.permission.ADD_VOICEMAIL" />

我试图在 xx.java 中注册,但它没有用。

MainActivity.java:

    protected VoiceBrocast mUiBroadcastReceiver;

       mUiBroadcastReceiver = new VoiceBrocast();
    IntentFilter mIntentFilter = new IntentFilter();
    mIntentFilter.addAction("android.intent.action.ACTION_NEW_VOICEMAIL");

 MainActivity.this.registerReceiver(mUiBroadcastReceiver, mIntentFilter);

VoiceBrocast.Java

公共类 VoiceBrocast 扩展 BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
        System.out.println("voicemail");
    }

}

当我收到语音邮件时,没有可打印的内容,我在 LogCat 中看不到“语音邮件”。

4

2 回答 2

0

访问此内容提供者所需的最低权限是 ADD_VOICEMAIL

你有这样的权限吗?

于 2013-04-11T07:55:37.080 回答
0

不确定 else 是错误的,但一个问题是:意图动作没有被调用"android.intent.action.ACTION_NEW_VOICEMAIL"但是"android.intent.action.NEW_VOICEMAIL"

也许您将它与 VoicemailContract 类上的常量名称(即VoicemailContract.ACTION_NEW_VOICEMAIL.

于 2013-04-24T17:25:46.833 回答