解决方案 »
- android 给GridView 一个监听 弹出Dialog为什么不能加按钮啊?
- 怎么给listview的每一项添加事件监听器
- 局域网和互联网的通信
- 如何调出android系统铃声列表??
- 一个布局的问题,20行代码
- 当在手机调试安卓程序,程序直接停止了,没有报异常怎么办?
- activity跳转时会黑屏,模拟器会显示程序无响应
- PC与安卓手机的蓝牙通信问题
- android 生命周期问题
- 求助:autocompletetextview中点击item的问题
- 目前安装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); }