【问题标题】:android - SMS Receive Broadcast receiver getting abortedandroid - SMS Receive Broadcast 接收器被中止
【发布时间】:2012-02-19 06:55:33
【问题描述】:

我正在开发一个不会将消息保存在收件箱中的 android SMS 应用程序。 我需要使用网络服务调用验证消息的内容,然后删除广播。

在 SMSReceiver 的 onReceive() 中

 if (messageBody.equals("somedata"))
    {

         Intent i  = new Intent(context,Webservice.class);//webservice validation
         i.putExtra("messageBody",messageBody)
         startService(i);  

    // Stop it being passed to the main Messaging inbox
         abortBroadcast();
    }

用于 web 服务调用的 Intentservice 永远不会被执行。接收器在此之前被中止。 我是android新手,所以请让我知道在广播接收器(SMS_RECEIVE)的onReceive()中启动的意图服务中进行网络服务调用是否正确。

【问题讨论】:

  • 您是否在您的 androidmainfest.xml 文件中授予了读取权限?
  • 是的,我已授予以下权限

标签: android broadcast


【解决方案1】:

使用日志记录来确保 equals() 返回 true。如果是这种情况,则可能是您在 onReceive() 中执行了一些耗时的操作,而 BroadcastReceiver 被杀死了。来自文档:

http://developer.android.com/reference/android/content/BroadcastReceiver.html#onReceive(android.content.Context, android.content.Intent)

该函数通常在其进程的主线程中调用,因此您不应该在其中执行长时间运行的操作(在考虑接收器被阻塞和候选者之前,系统允许超时 10 秒)被杀)。

【讨论】:

    【解决方案2】:

    可能是你的 messageBody 变量中的空格问题,

    请试试这个,

    if (messageBody.trim().equals("somedata"))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-01
      相关资源
      最近更新 更多