title: Detect when device file system is exposed through MTP to host computer
body: <p>I have a rather simple problem. My app creates files on memory card which are later copied by desktop computer through MTP protocol. I need to detect when device is connected to computer with USB cable and if MTP file exchange mode is not activated I need to ask user to activate it.</p>
  
  <p>My current attempt is like this:</p>
  
  <p><code>Intent usbConnCheckIntent = mContext.registerReceiver(this, new IntentFilter("android.hardware.usb.action.USB_STATE"));</code></p>
  
  <pre><code>@Override
  public void onReceive(Context context, Intent intent) {
      mCurrentlyConnected = (intent.getExtras().getBoolean("connected"));   
  
      mIsMTPMode = (intent.getExtras().getBoolean("mtp"));
  
      ...
  
  }
  </code></pre>
  
  <p>(constants taken from  <a href="https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/hardware/usb/UsbManager.java" rel="nofollow noreferrer">https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/hardware/usb/UsbManager.java</a>)</p>
  
  <p>I successfully receive USB connection / disconnection events but <code>MTP</code> extra always returns true, even if device is connected in charging mode. I suspect it is because for some reason MTP mode is always enabled (because device can be seen in Windows Explorer and also my desktop application detects it as MTP device), but file system exposure counts as a different event. How can I detect whether not only MTP is connected but also file system is exposed?</p>
  
  <p>I am testing on Xiaomi MI 2 device but other devices also have the same problem.</p>