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

妖精的绣舞 提交于 2019-12-11 12:41:50

问题


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

}

回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/22835024/kitkat-behaviour-sms-broadcast-receiver-not-working-after-fresh-installation-an

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