我有一个在清单中注册BroadcastReceiver
的应用
<receiver
android:name=".smsprocessing.SmsBroadcastReceiver"
android:exported="true"
android:permission="android.permission.BROADCAST_SMS">
<intent-filter android:priority="999">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
<action android:name="android.provider.Telephony.SMS_DELIVER" />
<action android:name="android.provider.Telephony.SMS_DELIVER_ACTION" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
当我对其进行测试时,它一直都可以正常工作,但是今天我尝试将短信发送到安装了该应用程序的手机上,而这已经有好几个小时了。在测试之前,该应用程序在此手机上的运行状况一直不错,但我一直在屏幕锁定或锁定后几分钟内对其进行测试。
当我几个小时不使用手机时,看来BroadcastReceiver
并没有被触发。收到了SMS并触发了股票消息应用程序,但是没有触发我的BroadcastReceiver(或者至少没有启动我从onReceive()
开始的前台服务)。
有问题的电话是运行Android 4.4.4的Motorola Moto G。
当我应该触发触发BroadcastReceiver的几分钟后通过USB连接手机时,我只会看到两个与我的应用相关的日志:
10-12 22:33:28.438 1039-1053/? I/ActivityManager: Start proc com.example.myapp for broadcast com.example.myapp/com.example.myapp.smsprocessing.SmsBroadcastReceiver: pid=3554 uid=10230 gids={50230, 3003}
10-12 22:33:28.961 1039-4323/? I/ActivityManager: Process com.example.myapp (pid 3554) has died.
这是(我认为)收到SMS时的完整日志(我在上面两行加上###
作为前缀):
10-12 22:33:28.235 1039-1186/? I/PackageManager: Adding preferred activity ComponentInfo{com.android.mms/com.android.mms.ui.ComposeMessageActivity} for user 0 :
10-12 22:33:28.271 1039-4323/? I/PackageManager: Adding preferred activity ComponentInfo{com.android.mms/com.android.mms.ui.ComposeMessageActivity} for user 0 :
10-12 22:33:28.291 1039-1401/? I/PackageManager: Adding preferred activity ComponentInfo{com.android.mms/com.android.mms.ui.ComposeMessageActivity} for user 0 :
10-12 22:33:28.312 1039-1100/? I/PackageManager: Adding preferred activity ComponentInfo{com.android.mms/com.android.mms.ui.ComposeMessageActivity} for user 0 :
10-12 22:33:28.345 1039-1053/? I/ActivityManager: Start proc com.android.mms for broadcast com.android.mms/.transaction.PrivilegedSmsReceiver: pid=3524 uid=10030 gids={50030, 3003, 1028, 1015}10-12 22:33:28.345 1039-1053/? I/ActivityManager: Start proc com.android.mms for broadcast com.android.mms/.transaction.PrivilegedSmsReceiver: pid=3524 uid=10030 gids={50030, 3003, 1028, 1015}
### 10-12 22:33:28.438 1039-1053/? I/ActivityManager: Start proc com.example.myapp for broadcast com.example.myapp/com.example.myapp.smsprocessing.SmsBroadcastReceiver: pid=3554 uid=10230 gids={50230, 3003}
10-12 22:33:28.635 1039-1093/? D/WifiService: Client connection lost with reason: 4
10-12 22:33:28.644 1039-1050/? I/ActivityManager: Start proc android.process.acore for content provider com.android.providers.contacts/.ContactsProvider2: pid=3571 uid=10010 gids={50010, 3003, 1028, 1015, 1023}
10-12 22:33:28.645 1039-4321/? I/ActivityManager: Process com.google.android.gms (pid 2593) has died.
10-12 22:33:28.648 1039-4321/? W/ActivityManager: Service ServiceRecord{43d5d0e0 u0 com.google.android.gms/.chimera.GmsApiService} in process ProcessRecord{425f9028 2593:com.google.android.gms/u0a22} not same as in map: null
10-12 22:33:28.649 1039-4321/? W/ActivityManager: Scheduling restart of crashed service com.google.android.gms/.chimera.GmsIntentOperationService in 26259ms
Scheduling restart of crashed service com.google.android.gms/.checkin.CheckinService in 26259ms
Service ServiceRecord{43116f88 u0 com.google.android.gms/.chimera.GmsBoundBrokerService} in process ProcessRecord{425f9028 2593:com.google.android.gms/u0a22} not same as in map: null
10-12 22:33:28.848 1039-1290/? I/ActivityManager: Start proc com.google.android.gms for service com.google.android.gms/.ads.identifier.service.AdvertisingIdService: pid=3618 uid=10022 gids={50022, 3003, 1007, 1028, 1015, 3002, 3001, 3007, 2001, 3006}
### 10-12 22:33:28.961 1039-4323/? I/ActivityManager: Process com.example.myapp (pid 3554) has died.
10-12 22:33:29.279 1039-1313/? I/ActivityManager: Process com.google.android.apps.photos (pid 3476) has died.
10-12 22:33:29.998 1039-1049/? I/ActivityManager: Process com.google.android.gms.unstable (pid 3285) has died.
10-12 22:33:30.227 1039-1093/? D/WifiService: New client listening to asynchronous messages
10-12 22:33:30.422 263-349/? W/Vold: Returning OperationFailed - no handler for errno 30
10-12 22:33:30.425 263-349/? W/Vold: Returning OperationFailed - no handler for errno 30
10-12 22:33:30.483 1039-1100/? I/ActivityManager: Start proc com.google.android.gms.unstable for service com.google.android.gms/.droidguard.DroidGuardService: pid=3693 uid=10022 gids={50022, 3003, 1007, 1028, 1015, 3002, 3001, 3007, 2001, 3006}
10-12 22:33:30.847 1039-4323/? I/ActivityManager: Process android.process.acore (pid 3571) has died.
10-12 22:33:31.308 1039-3556/? I/ActivityManager: Process com.android.mms (pid 3524) has died.