sendBroadcast发生java.lang.RuntimeException: has no zero argument constructor
时间: 2024-03-05 17:53:38 浏览: 100
这个问题通常是因为你的BroadcastReceiver没有提供默认构造函数(即没有参数的构造函数)。当你使用sendBroadcast发送广播时,系统会尝试实例化BroadcastReceiver,如果它没有默认构造函数,就会导致这个异常。
要解决这个问题,你可以在BroadcastReceiver中添加一个无参数的构造函数。例如:
```
public MyBroadcastReceiver() {
// 无参数的构造函数
}
```
或者你可以通过在Manifest文件中注册BroadcastReceiver时,使用android:name属性来指定BroadcastReceiver的完整类名,避免系统自动实例化BroadcastReceiver。例如:
```
<receiver
android:name=".MyBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
```
这样做可以确保系统不会实例化BroadcastReceiver,并且你可以在BroadcastReceiver中定义任何构造函数。
相关问题
06-01 06:12:00.539 0 0 W [GLUE]_MTGPDWNC_RequestSuspendEvent[3204]: u4SuspendEn=0x80100, u4SuspendEvent=0x4 . 06-01 06:11:59.702 1991 5539 W ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1111 android.content.ContextWrapper.sendBroadcast:468 com.mediatek.twoworlds.tv.TVCallback$6.run:838 java.lang.Thread.run:923 <bottom of call stack> 06-01 06:12:00.553 0 0 W : [GLUE]__Glue_PM_SetupEthernetWakeup Disable WOL!! 06-01 06:12:00.561 0 0 W : [GLUE]__Glue_PM_SetupEthernetWakeup (EEP_WOW = 0) _gi4PDWNCWifiWowState=1 !! 06-01 06:12:00.572 0 0 W : [GLUE]__Glue_PM_SetupEthernetWakeup (EEP_WOL = 0) !!
这是来自Android系统的一组日志,其中包含了多个模块的信息。具体来说:
- 第一个日志(第一行)来自GLUE模块,表示请求挂起事件,并且包含了一些参数信息。
- 第二个日志(第二行)来自ContextImpl模块,表示在没有经过授权的用户的情况下调用系统进程中的方法,具体是发送广播。
- 第三个日志(第三行)来自GLUE模块,表示禁用了以太网唤醒(Wake-on-LAN)功能。
- 第四个日志(第四行)来自GLUE模块,表示启用了以太网唤醒功能,并且设置了EEP_WOW参数。
- 第五个日志(第五行)来自GLUE模块,表示启用了以太网唤醒功能,并且设置了EEP_WOL参数。
这些日志都是系统或应用程序在执行一些操作时生成的。具体操作的含义需要查看模块的源代码才能确定。
分析蓝牙打印”05-22 20:55:15.340 3861 3861 W ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@1702c5f 05-22 20:55:15.405 3861 3861 W ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1005 android.content.ContextWrapper.sendBroadcast:444 com.zhiying.bluetoothmodelservice.MainActivity.sendBroadcast:643 com.zhiying.bluetoothmodelservice.MainActivity.onCreate:84 android.app.Activity.performCreate:7136 05-22 20:55:15.409 1936 5786 E ActivityManager: Sending non-protected broadcast android.newlink.exit.bluetoothSpeaker from system 3861:com.zhiying.bluetoothmodelservice/1000 pkg com.zhiying.bluetoothmodelservice 05-22 20:55:15.419 1936 5786 E ActivityManager: Sending non-protected broadcast android.newlink.exit.bluetoothSpeaker from system 3861:com.zhiying.bluetoothmodelservice/1000 pkg com.zhiying.bluetoothmodelservice 05-22 20:55:15.491 1797 1797 I MediaPlayerFactory: [getNameByPid:285] pid(3861), cmdline task_name(com.zhiying.bluetoothmodelservice). 05-22 20:55:15.561 3861 5918 W MediaPlayerNative: info/warning (710, 20) 05-22 20:55:15.562 3861 5918 W MediaPlayerNative: info/warning (710, 40) 05-22 20:55:15.610 3861 5918 W MediaPlayerNative: info/warning (710, 80) 05-22 20:55:15.628 3861 5918 W MediaPlayerNative: info/warning (710, 90) 05-22 20:55:15.628 3861 3861 I bt.sink.btconAc: true-------service-------- 05-22 20:55:15.628 3861 5918 W MediaPlayerNative: info/warning (710, 100) 05-22 20:55:15.629 3861 3861 W ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.startService:1531 android.content.ContextWrapper.startService:664 com.zhiying.bluetoothmodelservice.MainActivity.setBluetoothServiceStatus:354 com.zhiying.bluetoothmodelservice.MainActivity.initData:187 com.zhiying.bluetoothmodelservice.MainActivity.onCreate:89 05-22 20:55:15.649 3861 3861 I UartUtils: setState: true 05-22 20:55:15.649 3861 3861 I HiMW_TVClient: [invoke:53] =============invoke cmd = 0xf10a=======begin============= 05-22 20:55:15.653 3861 3861 I HiMW_TVClient: [invoke:65] =============invoke cmd = 0xf10a=======end=============== 05-22 20:55:15.654 3861 3861 W AudioManager: Use of stream types is deprecated for operations other than volume control 05-22 20:55:15.654 3861 3861 W AudioManager: See the documentation of requestAudioFocus() for what to use instead with android.media.AudioAttributes to qualify your playback use case 05-22 20:55:15.655 1936 5786 I MediaFocusControl: requestAudioFocus() from uid/pid 1000/3861 clientId=android.media.AudioManager@3140a29 callingPack=com.zhiying.bluetoothmodelservice req=2 flags=0x0 sdk=29 05-22 20:55:15.658 3861 3861 D bt.sink.btconAc: onResume: 05-22 20:55:15.658 3861 3861 D bt.sink.btconAc: getBreathingScreenDatas: Could not find remote control icon properties 05-22 20:55:15.702 3861 3861 I bt.sink.btsevice: blueToothChange:关闭 05-22 20:55:15.706 3861 3861 D BluetoothAdapter: enable(): BT already enabled! 05-22 20:55:15.738 3861 3894 I ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0 05-22 20:55:15.738 3861 3894 I ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retriev
此日志中记录了一个蓝牙打印相关的应用程序的运行过程。在这个应用程序中,MainActivity被创建并且sendBroadcast()方法被调用以发送广播。然后,系统收到了这个广播并且将其发送到了一个非保护的广播中,可能会被其他应用程序接收到。MediaPlayerFactory创建了一个新的MediaPlayer实例,同时MediaPlayerNative记录了一些信息和警告。BluetoothService状态被设置为true并且HiMW_TVClient执行了一些操作。最后,AudioManager请求了音频焦点并且BluetoothAdapter被启用。
阅读全文