Android 修改默认USB模式

Android 修改默认USB模式

android 7.0后修改为默认MTP

@Override
public void handleMessage(Message msg) {
    switch (msg.what) {
        case MSG_UPDATE_STATE:
            ......
            if (mBootCompleted) {
                if (!mConnected) {
                    // restore defaults when USB is disconnected
                    // 修改USB为默认MTP模式  {
                    // setEnabledFunctions(null, !mAdbEnabled, false);
                    setEnabledFunctions(UsbManager.USB_FUNCTION_MTP, false, true);
                    // }
                }
                updateUsbFunctions();
            } else {
                mPendingBootBroadcast = true;
            }
            break;
        case MSG_UPDATE_PORT_STATE:
        ......
        case MSG_BOOT_COMPLETED:
            mBootCompleted = true;
            if (mPendingBootBroadcast) {
                updateUsbStateBroadcastIfNeeded(false);
                mPendingBootBroadcast = false;
            }
            // 修改USB为默认MTP模式  {
            // setEnabledFunctions(null, false, false);
            setEnabledFunctions(UsbManager.USB_FUNCTION_MTP, false, true);
            // }
            if (mCurrentAccessory != null) {
                getCurrentSettings().accessoryAttached(mCurrentAccessory);
            }
            if (mDebuggingManager != null) {
                mDebuggingManager.setAdbEnabled(mAdbEnabled);
            }
            break;
        case MSG_USER_SWITCHED: {
        ......
}

你可能感兴趣的:(Android)