Android SMS_RECEIVED广播接收器未被调用

时间:2012-04-11 07:29:42

标签: android

我的bradcastreceiver中的onreceived函数未被触发。

我通过从不同的手机发送短信来测试这个,但日志似乎没有显示任何活动。

这是接收器类

package nz.co.smstopc;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class SmsListener extends BroadcastReceiver{

    @Override
    public void onReceive(Context context, Intent intent) {
        //---get the SMS message passed in---
        Log.d("SmsListener", "new sms!!");
    }
}

这是minifest.xml

 <receiver android:name=".smstopc.SmsListener"> 
        <intent-filter>                                         
            <action android:name="android.provider.Telephony.SMS_RECEIVED" /> 
        </intent-filter> 
    </receiver>

这是我使用过的权限。

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

我已经尝试过一切来解决这个问题。 我是否想念微小的东西?

2 个答案:

答案 0 :(得分:1)

我以同样的方式做到了,但我的Manifest-File看起来有点不同:

<receiver android:name=".receiver.SmsBroadcastReceiver" >
     <intent-filter android:priority="99999999" >
          <action android:name="android.provider.Telephony.SMS_RECEIVED" />
     </intent-filter>
</receiver>

答案 1 :(得分:0)

接收方中的包名可能与清单标记中的包属性冲突 试试这个

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="your package name"
...
...
...
<receiver android:name="nz.co.smstopc.SmsListener"> 
        <intent-filter>                                         
            <action android:name="android.provider.Telephony.SMS_RECEIVED" /> 
        </intent-filter> 
    </receiver>