简体   繁体   English

安卓系统 <receiver> -不调用BroadcastReceiver

[英]Android <receiver> - BroadcastReceiver not called

I have specified a receiver in the manifest like so .. 我已经在清单中指定了接收者,例如..

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.me.MyProject"
          android:versionCode="1"
          android:versionName="1.0">

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>

<application android:label="@string/app_name"
             android:icon="@drawable/ic_launcher" android:enabled="true">

    <service android:name="MyService" 
             android:exported="true"
             android:process=":different" 
             android:enabled="true">
        <intent-filter>
            <action android:name="com.me.MyService">
            </action>
        </intent-filter>
    </service>

    <receiver android:exported="true" 
              android:name="MySMSBroadcastReceiver" 
              android:enabled="true">
        <intent-filter>
            <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
        </intent-filter>
    </receiver>
</application>

If I test this on an Android Froyo device (emulator or real) this works as I expect. 如果我在Android Froyo设备(仿真器或真实设备)上对此进行了测试,则可以按预期运行。 The MySMSBroadcastReceiver.onReceive(...) is being called when the device receives an SMS. 设备接收到SMS时,将调用MySMSBroadcastReceiver.onReceive(...)。

However if I install this on a 4.0 or 4.1 device (either emulator or a real device) nothing happens on an incoming message. 但是,如果我将此安装在4.0或4.1设备(仿真器或真实设备)上,则传入消息不会发生任何事情。 No errors, no nothing. 没有错误,什么都没有。 I also changed the properties for the project to target a 4.0 or 4.1 device specifically and re-installed it but that makes no difference. 我还更改了项目的属性,以专门针对4.0或4.1设备,然后重新安装它,但这没什么区别。

从Android 3.1开始 ,在安装完应用程序后,用户需要手动启动您的活动,然后您的BroadcastReceivers中的任何一个才会生效。

您可以在操作系统启动时启动接收器,并提供正确的权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM