原生态的android中,PTP只支持本地存储设备,外部sd设备没有添加。但可以通过修改代码添加,前提是你必须要有android的源码,我的是在MTK平台下面开发的。

修改文件:

1:...\os\Enviroment.java

添加下面两行代码

public static String DIRECTORY_SD2_PICTURES = "Pictures2";    public static String DIRECTORY_SD2_DCIM = "DCIM2";
2: packages\privoiders\MediaProvider\src\com\android\providers\media\MtpService.java

//add for two PTP disk. start.  private static final String[] PTP_DIRECTORIES_SD2 = new String[] {         Environment.DIRECTORY_SD2_DCIM,         Environment.DIRECTORY_SD2_PICTURES,     };  //add for two PTP disk. end.

3.     private void addStorageDevicesLocked() {         /*if (mPtpMode) {             // In PTP mode we support only primary storage             final StorageVolume primary = StorageManager.getPrimaryVolume(mVolumes);             final String path = primary.getPath();             if (path != null) {                 String state = mStorageManager.getVolumeState(path);                 if (Environment.MEDIA_MOUNTED.equals(state)) {                     addStorageLocked(mVolumeMap.get(path));                 }             }         } else  cancelled. for PTP two disk. */{             for (StorageVolume volume : mVolumeMap.values()) {                 addStorageLocked(volume);             }         }     } 4.     @Override     public int onStartCommand(Intent intent, int flags, int startId) {         synchronized (mBinder) {             updateDisabledStateLocked();    isUsbConfigured = (intent == null ? false     :intent.getBooleanExtra(UsbManager.USB_CONFIGURED, false));            mPtpMode = (intent == null ? false                     : intent.getBooleanExtra(UsbManager.USB_FUNCTION_PTP, false));             String[] subdirs = null;             if (mPtpMode) {                 int count = PTP_DIRECTORIES.length;     int count2 = PTP_DIRECTORIES_SD2.length; //add. for PTP two disks.                 subdirs = new String[count+count2]; //add. for PTP two disk.                 for (int i = 0; i < count; i++) {                     File file =                             Environment.getExternalStoragePublicDirectory(PTP_DIRECTORIES[i]);                     // make sure this directory exists                     file.mkdirs();                     subdirs[i] = file.getPath();                 }     for (int i = count; i < count+count2; i++) { //modify. for PTP two disks.                          File file = new File(System.getenv("SECONDARY_STORAGE"), PTP_DIRECTORIES_SD2[i-count]);  //wqtao. modify. for PTP two disks.                                        // make sure this directory exists                     file.mkdirs();                     subdirs[i] = file.getPath();                 }             } 5.     private void volumeMountedLocked(String path) {         // Add for update Storage         StorageVolume[] volumes = mStorageManager.getVolumeList();         mVolumes = volumes;         // Add for update Storage         for (int i = 0; i < mVolumes.length; i++) {             StorageVolume volume = mVolumes[i];             if (volume.getPath().equals(path)) {                 mVolumeMap.put(path, volume);                 if (!mMtpDisabled) {                     // In PTP mode we support only primary storage                     /*if (volume.isPrimary() || !mPtpMode)   cancelled. for PTP two disk. */{                         addStorageLocked(volume);                     }                 }                 break;             }         }     }
先./mk [Your ProjectName] update-api,再remake.



更多相关文章

  1. 【代码】Android: 怎样设置app不被系统k掉
  2. android 源代码定制--- 状态栏
  3. Android 检测键盘显示或隐藏键盘的实现代码
  4. android launcher源码分析
  5. Android异步加载源码示例

随机推荐

  1. 【北亚数据恢复】HP P2000服务器 RAID5硬
  2. 初学者如何画好线条?练习画线条教学
  3. Eclipse阿里云镜像源配置
  4. 云服务器建站系列|如何优化网页访问速度?
  5. 2021.12.20 task
  6. Web Components系列(四) —— 认识 Shadow
  7. 如何从阿里云官方镜像站下载centos并安装
  8. 人物角色怎么画?画漫画人物基础教程!
  9. 意派Epub360丨情人节遇上元宵节,H5创意大
  10. 如何画线条?手绘人物线条教学!