全新安装且未启动应用程序后

全新安装且未启动应用程序后

本文介绍了Kitkat行为:全新安装且未启动应用程序后,SMS Broadcast Receiver无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序,可以收听SMS消息.这是在清单中:

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>

如果已安装并打开应用程序(对于所有android版本),则广播接收器可以正常工作.

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

  • 在低于kitkat版本的情况下,如果应用已安装但未打开,则仍会以OnRecieve方法接收短信

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

对于KitKat,它只有在启动应用程序一次后才起作用.

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

当我发送短信时,非Kitkat设备(GB版本)会收到短信,但Kitkat版本不会.

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

OnRecieve代码是:

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

}

推荐答案

在首次启动之前,应用不会接收广播.这是Android安全性.他们曾经能够这么做,但是Google最近已经改变了这种行为.

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.

这篇关于Kitkat行为:全新安装且未启动应用程序后,SMS Broadcast Receiver无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 01:43