问题
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