Skip to content

Commit

Permalink
改善sdcardutils
Browse files Browse the repository at this point in the history
  • Loading branch information
马天宇 committed Apr 20, 2015
1 parent b2d2c3f commit f6880cf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
28 changes: 18 additions & 10 deletions src/com/litesuits/common/utils/SdCardUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.litesuits.android.log.Log;

import java.io.*;
import java.util.ArrayList;

/**
* @author MaTianyu
Expand Down Expand Up @@ -42,6 +43,7 @@ public static String getNormalSDCardPath() {
*/
public static String getSDCardPath() {
String cmd = "cat /proc/mounts";
String sdcard = null;
Runtime run = Runtime.getRuntime();// 返回与当前 Java 应用程序相关的运行时对象
BufferedReader bufferedReader = null;
try {
Expand All @@ -54,8 +56,9 @@ public static String getSDCardPath() {
&& lineStr.contains(".android_secure")) {
String[] strArray = lineStr.split(" ");
if (strArray.length >= 5) {
String sdcard = strArray[1].replace("/.android_secure", "");
//return sdcard;
sdcard = strArray[1].replace("/.android_secure", "");
Log.i(TAG, "find sd card path: " + sdcard);
return sdcard;
}
}
if (p.waitFor() != 0 && p.exitValue() == 1) {
Expand All @@ -74,14 +77,16 @@ public static String getSDCardPath() {
e.printStackTrace();
}
}
return Environment.getExternalStorageDirectory().getPath();
sdcard = Environment.getExternalStorageDirectory().getPath();
Log.i(TAG, "not find sd card path return default: " + sdcard);
return sdcard;
}

/**
* 查看所有的sd路径
*/
public static String getSDCardPathEx() {
String mount = "";
public static ArrayList<String> getSDCardPathEx() {
ArrayList<String> list = new ArrayList<String>();
try {
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("mount");
Expand All @@ -101,12 +106,12 @@ public static String getSDCardPathEx() {
if (line.contains("fat")) {
String columns[] = line.split(" ");
if (columns.length > 1) {
mount = mount.concat("*" + columns[1] + "\n");
list.add("*" + columns[1]);
}
} else if (line.contains("fuse")) {
String columns[] = line.split(" ");
if (columns.length > 1) {
mount = mount.concat(columns[1] + "\n");
list.add(columns[1]);
}
}
}
Expand All @@ -115,15 +120,18 @@ public static String getSDCardPathEx() {
} catch (IOException e) {
e.printStackTrace();
}
return mount;
return list;
}

//获取当前路径,可用空间
/**
* 获取当前路径,可用空间
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static long getAvailableSize(String path) {
try {
File base = new File(path);
StatFs stat = new StatFs(base.getPath());
return stat.getBlockSizeLong() * ((long) stat.getAvailableBlocksLong());
return stat.getBlockSizeLong() * stat.getAvailableBlocksLong();
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
8 changes: 4 additions & 4 deletions src/com/litesuits/common/utils/TelephoneUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public static TeleInfo getMtkTeleInfo(Context context) {
} catch (Exception e) {
e.printStackTrace();
}
Log.i(TAG, teleInfo);
Log.i(TAG, "MTK: " + teleInfo);
return teleInfo;
}

Expand Down Expand Up @@ -202,7 +202,7 @@ public static TeleInfo getMtkTeleInfo2(Context context) {
} catch (Exception e) {
e.printStackTrace();
}
Log.i(TAG, teleInfo);
Log.i(TAG, "MTK2: " + teleInfo);
return teleInfo;
}

Expand Down Expand Up @@ -238,7 +238,7 @@ public static TeleInfo getQualcommTeleInfo(Context context) {
} catch (Exception e) {
e.printStackTrace();
}
Log.i(TAG, teleInfo);
Log.i(TAG, "Qualcomm: " + teleInfo);
return teleInfo;
}

Expand Down Expand Up @@ -273,7 +273,7 @@ public static TeleInfo getSpreadtrumTeleInfo(Context context) {
} catch (Exception e) {
e.printStackTrace();
}
Log.i(TAG, teleInfo);
Log.i(TAG, "Spreadtrum: " + teleInfo);
return teleInfo;
}
}

0 comments on commit f6880cf

Please sign in to comment.