简体   繁体   中英

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. The MySMSBroadcastReceiver.onReceive(...) is being called when the device receives an SMS.

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. 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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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