Kitkat Behaviour: SMS Broadcast Receiver not working after fresh installation and if app is not launched

StackOverflow https://stackoverflow.com/questions/22835024

  •  26-06-2023
  •  | 
  •  

Question

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" );
    }

}
Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top