未在 Android 6 上调用 SMS 广播接收器

SMS Broadcast Receiver not called on Android 6

我正在尝试捕获在 phone 上收到的 SMS,但是当 phone 收到 SMS 消息时,方法 'onReceive' 没有被调用。这是我的代码:

我在 'AndroidManifest.xml' 标签内声明了 BroadcastReceiver 'application':

    <receiver android:name=".util.IncomingSmsReceiver"
        android:exported="true">
        <intent-filter android:priority="2147483647">
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
        </intent-filter>
    </receiver>

这是IncomingSmsReceiver.java

public class IncomingSmsReceiver extends BroadcastReceiver {

    public static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";

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

        Log.i(TAG, "onReceive executed");
        if (intent.getAction().equals(SMS_RECEIVED)) {
           ...
        }
   }
}

我正在模拟器上进行测试 Google Nexus 5 与 Android 6。当我在模拟器中发送短信(假)时,会出现一条通知,就好像它收到得很好我可以在自带模拟器的默认应用程序中使用它。在 Android Studio 的 logcat 中没有出现您有 运行 方法 onReceive,或者编写的代码 inside.I 试图更改优先级,我试过使用 android:enabled="true",我试过使用 registerReceiver 但我没有让它工作。有人知道我是否遗漏了什么吗?

您使用的是启用了 "Disable other apps" 标志的默认消息传递应用程序吗?

请看这个:

"android.provider.Telephony.SMS_RECEIVED" not working on my device (HTC Wildfire) - how to debug?

编辑:

由于您使用的是 Android6,因此您应该使用新的权限模型。看一下这个: http://developer.android.com/training/permissions/requesting.html