王者地带 - 5+混合APP开发教程网 | http://www.html5-app.com | ***: 2564034335
的回复:
var main = plus.android.runtimeMainActivity(); var receiver = plus.android***plements('io.dcloud.feature.internal.reflect.BroadcastReceiver',{onReceive:getReceive}); var IntentFilter = plus.android***portClass('android.content.IntentFilter'); var Intent = plus.android***portClass('android.content.Intent'); var filter= new IntentFilter(); var action="android.hardware.usb.action.USB_STATE"; filter.addAction(action); main.registerReceiver(receiver, filter); function getReceive(context,intent) { var type= intent.getAction(); if(type==action) { var connected=intent.getExtras(); plus.android***portClass(connected); var isusb=connected.getBoolean("connected"); if(isusb) { uni.showToast({title:"USB 已连接",icon:"none"}); }else{ uni.showToast({title:"USB 已拔出",icon:"none"}); } } }