无法从收到的消息中接收广播

时间:2011-03-11 03:44:06

标签: android broadcastreceiver

我在以下AndroidManifest.xml中声明了BroadcastReceiver,但我从未收到过SMS_RECEIVED广播。有什么想法发生了什么?

这是BroadcastReceiver

public class SMSReceiver1 extends BroadcastReceiver 
{ 
    private static final String LOG_TAG = "Thiri The Wut Yee";

    private static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";

    public void onReceive(Context context, Intent intent) 
    {
        Log.i(LOG_TAG, "Receive ");
        Toast.makeText(context, "RECEIVED", Toast.LENGTH_LONG).show();
    }
}

AndroidManifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="android_programmers_guide.SMSReceiver1"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <receiver android:name=".SMSReceiver1"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
            </intent-filter>
       </receiver>
    </application>
    <uses-sdk android:minSdkVersion="4" />
</manifest> 

1 个答案:

答案 0 :(得分:1)

你的清单中有这个权限吗?

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