Android: Detecting USB

前端 未结 6 1866
一生所求
一生所求 2020-11-27 06:13

Is there any way to know(programmatically) in your Activity/Application that the user has connected your phone to PC through USB?

6条回答
  •  天命终不由人
    2020-11-27 06:32

    Was able to detect USB connection by registering a broadcast receiver by following,

    IntentFilter mIntentFilter = new IntentFilter(Intent.ACTION_UMS_CONNECTED);
    
    BroadcastReceiver bd = new intentReceiver();
    registerReceiver(bd, mIntentFilter);
    
    

提交回复
热议问题