如何在Android中访问USB路径? [英] How to access USB Path in android?

查看:192
本文介绍了如何在Android中访问USB路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过USB电缆连接了android设备和PC.我的内部SD卡位置路径为/mnt/sdcard .但是我的外部USB设备路径为/mnt/userdata1 .我尝试使用此代码仅查找内部SD卡路径 Environment.getExternalStorageDirectory().我正在使用此代码仅在内部SD卡路径中访问.如何访问外部USB路径.

I am connected android device and PC via USB cable. My Internal SD Card location Path as /mnt/sdcard. But my External USB device path as /mnt/userdata1. I am try to use this code to find only the Internal SD Card Path Environment.getExternalStorageDirectory(). I am using this code to access only in the internal SD Card path. How to access the external USB Path.

例如,屏幕截图在这里...

For example Screenshot is here... Example

In this example contains Internal Memory, External SD card and USB Storage. How to find this path ( Internal Memory, External SD card and USB Storage) programmatically. In this code Environment.getExternalStorageDirectory() is viewed files from all Internal Memory Files only. So how to access others path ( External SD card and USB Storage )

Please guide me with code. Thanks..

推荐答案

如果我正确理解,您所说的外部" USB路径实际上是计算机上SD卡的安装点.您的SD卡很可能带有标签 userdata1 .因此,当它安装在计算机上时,它会获得/mnt/userdata1 挂载点.但是,这并非绝对必要,它可以是任何安装点.实际上,如果将其连接到另一台计算机,它很容易成为另一个安装点.

If I understand correctly, what you are calling "external" USB path is actually the mount point for your SD card on your computer. Most likely, your SD card has label userdata1. Therefore when it's mounted on the computer, it gets /mnt/userdata1 mount point. However this is not strictly necessary and it can be any mount point at all. In fact, if you connect it to another computer, it can easily be another mount point.

由于此路径是由计算机操作系统确定的,因此您需要在计算机上找到该路径(请注意,每次将手机连接到PC时,该路径都可能不同.每次).

Because this path is determined by the computer operating system, you'll need to find this path on your computer (note that this can be different every time you connect your phone to your PC, so you'll need to do it every time).

根据您的问题和路径结构(/mnt/userdata1 ),我猜测您使用的是Linux或其他某些Unix版本.因此,您可以在PC上运行 mount 来查看已安装设备的列表.例如,这是我的mac电脑上的输出:

From your question and path structure (/mnt/userdata1) I'm guessing you're using linux or some other unix version. Therefore you could run mount on your PC to see the list of the mounted devices. For example, here's the output on my mac:

$ mount
/dev/disk0s2 on / (hfs, local, journaled)
devfs on /dev (devfs, local, nobrowse)
map -hosts on /net (autofs, nosuid, automounted, nobrowse)
map auto_home on /home (autofs, automounted, nobrowse)
/dev/disk1s1 on /Volumes/ALEKS540 (msdos, local, nodev, nosuid, noowners)

请注意输出中的最后一行-这是我连接的android手机,其中SD卡已安装到计算机上.在Mac上,挂载点是在/Volumes 下创建的,而不是在/mnt 下创建的.除了 ALEKS540 是我的SD卡的标签,因此它是通过这种方式安装的.

Note the last line in the output - this is my connected android phone with the SD card mounted to the computer. On macs, the mount points are created under /Volumes instead of /mnt. Other than than, ALEKS540 is the label of my SD card, hence it's mounted this way.

在手机内部,它仍以/mnt/sdcard 挂载.

Internally on the phone, it's still mounted as /mnt/sdcard.

从Android的角度来看,可能存在三种存储类型:

From the point of view of Android, there may be three storage types:

  1. 内部存储器,它始终安装在设备上的/下,并且包含除SD卡和下面的USB存储设备之外的所有内容.
  2. SD卡-称为外部存储",通常安装为/mnt/sd ,但并非总是如此. Environment.getExternalStorageDirectory()将返回SD卡安装点的路径.
  3. USB存储设备-仅在极少数设备(支持USB主机模式的外部存储设备)上支持.该文件将安装在/mnt 下的某个位置,但实际位置会有所不同.您将需要使用Android NDK来查询和迭代已安装的设备,以找到所要寻找的设备.
  1. Internal memory it's always mounted under / on the device and contains everything except the SD card and USB storage below.
  2. SD card - this is referred to as "external storage" and is usually mounted as /mnt/sd, but not always. Environment.getExternalStorageDirectory() will return the path of SD card mount point.
  3. USB storage - this is only supported on very few devices (those that support USB host mode for external storage). This will be mounted somewhere under /mnt, but the exact location will vary. You will need to use Android NDK to interrogate and iterate mounted devices to find the one you're after.

这篇关于如何在Android中访问USB路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆