我的应用使用WebView
来显示一些内容。有一天,我开始从用户那里收到以下错误:
Fatal Exception: java.lang.RuntimeException: Error receiving broadcast Intent { act=android.hardware.usb.action.USB_DEVICE_ATTACHED flg=0x10 pkg=com.chessking.android.learn.ctforbeginners } in org.chromium.media.AudioManagerAndroid$5@13883a1
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:891)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5420)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'int android.hardware.usb.UsbDevice.getInterfaceCount()' on a null object reference
at org.chromium.media.AudioManagerAndroid.hasUsbAudioCommInterface(AudioManagerAndroid.java:1224)
at org.chromium.media.AudioManagerAndroid.access$1200(AudioManagerAndroid.java:43)
at org.chromium.media.AudioManagerAndroid$5.onReceive(AudioManagerAndroid.java:1254)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:881)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5420)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
我看过AudioManagerAndroid.java代码,错误所在
if (!hasUsbAudioCommInterface(device)) return;
device
为空:
....
mUsbAudioReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
UsbDevice device = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (DEBUG) {
logd("UsbDeviceBroadcastReceiver.onReceive: a= " + intent.getAction()
+ ", Device: " + device.toString());
}
// Not a USB audio device.
if (!hasUsbAudioCommInterface(device)) return;
....
如何在不更改铬源的情况下避免该问题?我的WebView
从不使用音频。有没有一种方法可以不订阅音频事件?