Create an automatic launch-able Broadcast Receiver in Android

妖精的绣舞 提交于 2019-12-02 12:39:14

You need to add an activity, then run that activity, before this BroadcastReceiver will work.

More accurately, something needs to use an explicit Intent before your app will be moved out of the stopped state and allow manifest-registered BroadcastReceivers to work. The simplest way to do that is to have a launcher activity, and run that activity from the launcher.

To learn more, see "Launch controls on stopped applications" in the Android 3.1 release notes, along with this blog post.

Your Code look like this in manifest file

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

Add the following to your<receiver> in the manifest:

android:enabled="true" android:exported="true">

Furthermore, according to this thread, it seems that you have to manually start one of your activities before the broadcast receiver will start working, i.e. the application has to have been launched at least once before any broadcast receiver will work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!