如何区分Android storage USB memory和 Sdcard

由于现在做平板开发,必须得分出这2个存储。
USB memory和 sdcard
一般就看Enviroment类的源码。
public static File getExternalStorageDirectory() {
// Try to be smarter
// Return EXTERNAL_STORAGE_DIRECTORY_SD if SD card is ready
// Return EXTERNAL_STORAGE_DIRECTORY_UDISK if SD card is absent but udisk is ready
// Return EXTERNAL_STORAGE_DIRECTORY_SD if both sd card and udisk are not ready
String propSD = SystemProperties.get("EXTERNAL_STORAGE_STATE_SD", MEDIA_REMOVED);
String propUDISK = SystemProperties.get("EXTERNAL_STORAGE_STATE_UDISK", MEDIA_REMOVED);
String propEXTSD = SystemProperties.get("EXTERNAL_STORAGE_STATE_EXTSD", MEDIA_REMOVED);
if (propSD.equals(MEDIA_MOUNTED) || propSD.equals(MEDIA_MOUNTED_READ_ONLY)) {
return EXTERNAL_STORAGE_DIRECTORY_SD;
} else if (propUDISK.equals(MEDIA_MOUNTED) || propUDISK.equals(MEDIA_MOUNTED_READ_ONLY)) {
return EXTERNAL_STORAGE_DIRECTORY_UDISK;
} else if (propEXTSD.equals(MEDIA_MOUNTED) || propEXTSD.equals(MEDIA_MOUNTED_READ_ONLY)) {
return EXTERNAL_STORAGE_DIRECTORY_EXTSD;
} else {
return EXTERNAL_STORAGE_DIRECTORY_SD;
}
}

然后
 Environment.getExternalStorageDirectory().getAbsolutePath()

看返回的是"/sdcard"还是"/udisk"既可。
如果你直接指定这2个路径,去得到里面的文件时,是错误的!因为android里面默认会有/sdcard和/udisk目录,也就是说,你必须监听MEDIA_MOUNTED之后去Environment.getExternalStorageDirectory().getAbsolutePath()来判断路径!
### ADB Platform Tools and Usage #### Overview of Android Debug Bridge (ADB) Android Debug Bridge (ADB) is a versatile tool that allows developers to communicate with an Android device over USB or TCP/IP. This communication facilitates debugging applications directly on the device, transferring files between a computer and the device, issuing shell commands, etc.[^5] #### Components Involved in ADB Operations The operation of ADB involves three components: - **Client**: Runs on the developer's machine. Developers can invoke this client through a shell using `adb` commands; other tools like the ADT plugin and DDMS also initiate ADB clients. - **Daemon (`adbd`)**: Resides on each emulator instance or connected physical device. - **Server**: Manages communication between the client and daemon(s). It listens for connections from the client and forwards requests to the appropriate daemon instances running on emulators/devices. #### Common Commands Used With ADB To interact effectively via ADB, several key commands are frequently utilized: - Listing all active devices/emulators: ```bash adb devices ``` - Executing shell commands remotely on the device: ```bash adb shell ls /data/local/tmp/ ``` - Pushing local files onto the device storage: ```bash adb push myfile.txt /sdcard/myfile.txt ``` - Pulling remote files back to the host system: ```bash adb pull /sdcard/myfile.txt . ``` When multiple devices connect simultaneously but no specific target has been designated when executing certain operations, errors may occur because ADB cannot determine which one should receive instructions[^4]. #### Advanced Features Provided By ADB Beyond basic file transfer capabilities, more advanced features include monitoring log messages generated during application execution, capturing screenshots, controlling screen orientation changes programmatically, managing network settings, simulating incoming calls/SMSs, among others. For example, switching into the DDMS perspective within Eclipse IDE provides access to various utilities including viewing debug processes, updating threads information, inspecting heap memory usage patterns, forcing garbage collection cycles, stopping ongoing tasks gracefully, taking snapshots of current display contents visually, resetting connectivity status safely without disrupting overall workflow significantly[^1]. --related questions-- 1. How does ADB handle situations where there are multiple connected devices? 2. What types of actions can be performed using ADB beyond simple file transfers? 3. Can you explain how to use DDMS alongside ADB for enhanced debugging experiences? 4. In what scenarios might someone need to reset ADB? What effects would it have? 5. Are there any limitations imposed by different versions of Android regarding ADB functionality?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值