接收在KitKat上播放的短信

时间:2014-11-07 16:41:25

标签: android smsmanager

我真的尝试过这一切,广播接收器不接收新传入的短信广播。 我在手机上运行4.4.4,我只是想收听收到的消息,就是这样。

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


<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <receiver android:name=".SmsReceiver"
        android:enabled="true"
        >
        <intent-filter>
            <action android:name="android.provider.Telephony.SMS_RECEIVED_ACTION" />
        </intent-filter>
    </receiver>
</application>

广播接收器:

public class SmsReceiver extends BroadcastReceiver {

public SmsReceiver() {}

@Override
public void onReceive(Context context, Intent intent) {

    Log.d("v", "SMS onReceive");
}

的gradle:

android {
compileSdkVersion 20
buildToolsVersion "21.0.0"

defaultConfig {
    applicationId "com.dev.xxx"
    minSdkVersion 19
    targetSdkVersion 20
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    }
}

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:support-v4:+'
    }

1 个答案:

答案 0 :(得分:1)

您在清单中<action>的{​​{1}}中定义的<receiver>不正确。它应该是:

<intent-filter>

您可能会将它与类常量字符串标识符 <action android:name="android.provider.Telephony.SMS_RECEIVED" /> 混淆,后者具有上面显示的值。