/
获取手机自身内存路径
/
public static String getPhoneCardPath(){
return EnvironmentgetDataDirectory()getPath();
}
/
获取sd卡路径
双sd卡时,根据”设置“里面的数据存储位置选择,获得的是内置sd卡或外置sd卡
@return
/
public static String getNormalSDCardPath(){
return EnvironmentgetExternalStorageDirectory()getPath();
}
/
获取sd卡路径
双sd卡时,获得的是外置sd卡
@return
/
public static String getSDCardPath() {
String cmd = "cat /proc/mounts";
Runtime run = RuntimegetRuntime();// 返回与当前 Java 应用程序相关的运行时对象
BufferedInputStream in=null;
BufferedReader inBr=null;
try {
Process p = runexec(cmd);// 启动另一个进程来执行命令
in = new BufferedInputStream(pgetInputStream());
inBr = new BufferedReader(new InputStreamReader(in));
String lineStr;
while ((lineStr = inBrreadLine()) != null) {
// 获得命令执行后在控制台的输出信息
Logi("CommonUtil:getSDCardPath", lineStr);
if (lineStrcontains("sdcard")
&& lineStrcontains("android_secure")) {
String[] strArray = lineStrsplit(" ");
if (strArray != null && strArraylength >= 5) {
String result = strArray[1]replace("/android_secure",
"");
return result;
}
}
// 检查命令是否执行失败。
if (pwaitFor() != 0 && pexitValue() == 1) {
// pexitValue()==0表示正常结束,1:非正常结束
Loge("CommonUtil:getSDCardPath", "命令执行失败!");
}
}
} catch (Exception e) {
Loge("CommonUtil:getSDCardPath", etoString());
//return EnvironmentgetExternalStorageDirectory()getPath();
}finally{
try {
if(in!=null){
inclose();
}
} catch (IOException e) {
// TODO Auto-generated catch block
eprintStackTrace();
}
try {
if(inBr!=null){
inBrclose();
}
} catch (IOException e) {
// TODO Auto-generated catch block
eprintStackTrace();
}
}
return EnvironmentgetExternalStorageDirectory()getPath();
}
//查看所有的sd路径
public String getSDCardPathEx(){
String mount = new String();
try {
Runtime runtime = RuntimegetRuntime();
Process proc = runtimeexec("mount");
InputStream is = procgetInputStream();
InputStreamReader isr = new InputStreamReader(is);
String line;
BufferedReader br = new BufferedReader(isr);
while ((line = brreadLine()) != null) {
if (linecontains("secure")) continue;
if (linecontains("asec")) continue;
if (linecontains("fat")) {
String columns[] = linesplit(" ");
if (columns != null && columnslength > 1) {
mount = mountconcat("" + columns[1] + "\n");
}
} else if (linecontains("fuse")) {
String columns[] = linesplit(" ");
if (columns != null && columnslength > 1) {
mount = mountconcat(columns[1] + "\n");
}
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
eprintStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
eprintStackTrace();
}
return mount;
}
//获取当前路径,可用空间
public static long getAvailableSize(String path){
try{
File base = new File(path);
StatFs stat = new StatFs(basegetPath());
long nAvailableCount = statgetBlockSize() ((long) statgetAvailableBlocks());
return nAvailableCount;
}catch(Exception e){
eprintStackTrace();
}
return 0;
}
呃,一般原生系统貌似都没有集成文件管理器。不过不用你那么麻烦,你刷机应该是卡刷吧,刷机之前先在电脑里头把下载好的ES或RE文件管理器的安装包,放到下载好的刷机包里就是了,直接拖拽进去,不要改变原刷机包的属性等参数。
拖拽目录:system/app
public long getSDAllSize(){ //取得SD卡文件路径 File path = EnvironmentgetExternalStorageDirectory(); StatFs sf = new StatFs(pathgetPath()); //获取单个数据块的大小(Byte) long blockSize = sfgetBlockSize(); //获取所有数据块数 long allBlocks = sfgetBlockCount(); //返回SD卡大小 //return allBlocks blockSize; //单位Byte //return (allBlocks blockSize)/1024; //单位KB return (allBlocks blockSize)/1024/1024; //单位MB }
以上就是关于如何正确获得Android内外SD卡路径全部的内容,包括:如何正确获得Android内外SD卡路径、在android/安卓系统里怎样找到SD卡、android如何获取外部存储卡的容量等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)