解决方案 »
- 用Usb host方式获得usb设备列表为什么为空!!!
- 怎样在布局中对几个按钮实现想office2010中的两端对齐效果
- anroid虚拟机问题
- webview显示问题
- Android 2.3的webkit中如何支持Javascript的defer属性
- 【Android】SQLite 数据库查询问题
- 新建的XML下面有黄线~~
- 如何用代码控制Tabhost显示在屏幕下方?
- android 中ListView的Item中弹出的自定义的菜单的位置问题!
- APP怎样点一次手机物理反回键返回,点两次退出APP
- 目前安装android的SDK,在线安装的那种一直提示 google的文件找不到,没办法安装,求完整版SDK地址
- Android studio 运行错误
public String getOutSDPath() {
String mount = new String(); try {
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("mount");
InputStream is = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
String line; BufferedReader br = new BufferedReader(isr);
while ((line = br.readLine()) != null) {
if (line.contains("secure"))
continue;
if (line.contains("asec"))
continue; if (line.contains("fat")) {
String columns[] = line.split(" ");
if (columns != null && columns.length > 1) {
mount = mount.concat("*" + columns[1] + "\n");
}
} else if (line.contains("fuse")) {
String columns[] = line.split(" ");
if (columns != null && columns.length > 1) {
mount = mount.concat(columns[1] + "\n");
}
}
}
Log.i("外置SD卡或者USB设备路径", mount); } catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return mount;
}
public class MainActivity extends Activity {
private final String TAG = "MainActivity"; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView internalMemoryTextView = (TextView) findViewById(R.id.rom_left);
TextView externalMemoryTextView = (TextView) findViewById(R.id.inside_sd_left);
TextView sdCard2MemoryTextView = (TextView) findViewById(R.id.outside_sd_left);
internalMemoryTextView.setText("rom left "
+ getAvailableInternalMemorySize() + "MB");
externalMemoryTextView.setText("rom left "
+ getAvailableExternalMemorySize() + "MB");
sdCard2MemoryTextView.setText("rom left "
+ getAvailableSDCard2MemorySize() + "MB"); } /**
*
* @return ROM存储路径
*/
private String getInternalMemoryPath() {
return Environment.getDataDirectory().getPath();
} /**
*
* @return 内置sd卡路径
*/
private String getExternalMemoryPath() {
// return Environment.getExternalStorageDirectory().getPath();
return "/mnt/sdcard";
} /**
*
* @return 外置sd卡路径
*/
private String getSDCard2MemoryPath() {
return "/mnt/sdcard1";
} /**
*
* @param path
* 文件路径
* @return 文件路径的StatFs对象
* @throws Exception
* 路径为空或非法异常抛出
*/
private StatFs getStatFs(String path) {
try {
return new StatFs(path);
} catch (Exception e) {
e.printStackTrace();
}
return null;
} /**
*
* @param stat
* 文件StatFs对象
* @return 剩余存储空间的MB数
*
*/
private float calculateSizeInMB(StatFs stat) {
if (stat != null)
return stat.getAvailableBlocks()
* (stat.getBlockSize() / (1024f * 1024f));
return 0.0f;
} /**
*
* @return ROM剩余存储空间的MB数
*/
private float getAvailableInternalMemorySize() { String path = getInternalMemoryPath();// 获取数据目录
StatFs stat = getStatFs(path);
return calculateSizeInMB(stat);
} /**
*
* @return 内置SDCard剩余存储空间MB数
*/
private float getAvailableExternalMemorySize() { String path = getExternalMemoryPath();// 获取数据目录
StatFs stat = getStatFs(path);
return calculateSizeInMB(stat); } /**
*
* @return 外置SDCard剩余存储空间MB数
*/
private float getAvailableSDCard2MemorySize() { // String status = Environment.getExternalStorageState();
// if (status.equals(Environment.MEDIA_MOUNTED)) {
// }
String path = getSDCard2MemoryPath(); // 获取数据目录
StatFs stat = getStatFs(path);
return calculateSizeInMB(stat); }