Kitkat Behaviour: SMS Broadcast Receiver not worki

2019-08-10 15:42发布

I have an Android app that listens to SMS messages. This is in the manifest:

<receiver android:name=".SMSListner" >
 <intent-filter>
   <action android:name="android.provider.Telephony.SMS_RECEIVED" />
 </intent-filter>
</receiver>

The broadcast receivers works fine if the app is installed and opened(For all android versions).

  • In case, below kitkat version, if app is install and is not open, still it receives the SMS in OnRecieve method

  • In case of KitKat, it is not working till the time application is launched once.

When I send a SMS, non Kitkat device(GB version) receives the sms but Kitkat version doesnot.

OnRecieve code is:

public void onReceive( Context context, Intent intent )
{

    String action = intent.getAction();
    Log.v( "KK TEST APP", "===============SMS Received===============" );
    if ( action.equals( ACTION_SMS_RECEIVED ) )
    {
        Log.v( "KK TEST APP", "action.equals( ACTION_SMS_RECEIVED )" );
    }
    else
    {
        Log.v( "KK TEST APP", "other message" );
    }

}

2条回答
一夜七次
2楼-- · 2019-08-10 15:57

Apps will not receive broadcasts until they have been launched the first time. This is Android security. They used to be able to, but Google has changed this behavior somewhat recently.

查看更多
狗以群分
3楼-- · 2019-08-10 16:14

You can create a service to call a broadcast receiver. Also, in onCreate method in main activity call this service and this should remain active although your app is killed. Regrads

查看更多
登录 后发表回答