SMS_RECEIVED当App进程处于非活动状态时,不会触发BroadcastReceiver

时间:2017-09-02 02:22:37

标签: android broadcastreceiver

我已注册广播接收器以收听传入的短信。我观察到如果我的App进程未激活,广播接收器不会触发。

的AndroidManifest.xml

<receiver android:name=".SmsBroadcastReceiver"
                  android:enabled="true"
                  android:exported="true"
                  android:permission="android.permission.BROADCAST_SMS">
            <intent-filter android:priority="999">
                <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
            </intent-filter>
        </receiver>

SmsBroadcastReceiver.java

public class SmsBroadcastReceiver extends BroadcastReceiver {

    private static final String TAG = SmsBroadcastReceiver.class.getSimpleName();

    @Override
    public void onReceive(Context context, Intent intent) {
            Log.e(TAG, "New SMS-message received");
        }
    } 
}

我已将日志消息放在应用程序的onCreate回调上,并且我确认在设备上收到短信时,也未调用应用程序的onCreate。

Android版本 - 6.0.1 设备 - OnePlus 2

0 个答案:

没有答案