我使用ACTION_MEDIA_MOUNTED和ACTION_MEDIA_UNMOUNTED来检测Nexus 4上的USB连接,但无法接收任何广播信号.
这是我的广播接收器代码:
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
filter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
filter.addDataScheme("file");
debugReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (Intent.ACTION_MEDIA_MOUNTED.equals(action)) {
debugOn = true;
} else if (Intent.ACTION_MEDIA_UNMOUNTED.equals(action)) {
debugOn = false;
}
}
};
registerReceiver(debugReceiver, filter);
有任何想法吗?我还搜索了其他问题;他们说如果我加
“ filter.addDataScheme(” file“);”
我会收到信号,但是我已经尝试过,但是什么也没收到.
最后
以上就是端庄薯片最近收集整理的关于android判断usb已连接,如何在Android 4.2中检测USB连接?的全部内容,更多相关android判断usb已连接,如何在Android内容请搜索靠谱客的其他文章。
发表评论 取消回复