Cara ini berfungsi pada device - device samsung
public static ArrayList<String> getExternalSDCard()
{
String s = "";
ArrayList<String> result = new ArrayList<String>();
try
{
Process process = new ProcessBuilder().command("mount").redirectErrorStream(true).start();
process.waitFor();
InputStream is = process.getInputStream();
byte[] buffer = new byte[1024];
while (is.read(buffer) != -1)
{
s = s + new String(buffer);
}
is.close();
}
catch (Exception e)
{
e.printStackTrace();
}
String[] lines = s.split("\n");
for(int i=0; i<lines.length; i++)
{
//path[0]
if(-1 != lines[i].indexOf("/mnt") && -1 != lines[i].indexOf("vfat") )
{
String[] blocks = lines[i].split("\\s");
Log.i("
SDCARD ","ketemu fvat :" + lines[i]);
for(int j=0; j<blocks.length; j++)
{
if(-1 != blocks[j].indexOf("/") && -1==blocks[j].indexOf("/dev"))
{
try{
File f = new File(blocks[j]);
if(f.exists()){
Log.i("
SDCARD","DITAMBAHKAN " + blocks[j]);
result.add(blocks[j]);
}
}catch(Exception e){
}
}
}
}
else
{
Log.d("SDCARD","Not an SDCard / External Storage" + lines[i]);
}
}
//try to find fuse file system in /mnt/sdcard
for(int i=0; i<lines.length; i++)
{
//path[0]
if(-1 != lines[i].indexOf("/mnt/sdcard") && -1 != lines[i].indexOf("fuse rw") )
{
String[] blocks = lines[i].split("\\s");
Log.i("
SDCARD ","found fuse rw :" + lines[i]);
for(int j=0; j<blocks.length; j++)
{
if(-1 != blocks[j].indexOf("/") && -1==blocks[j].indexOf("/dev"))
{
try{
File f = new File(blocks[j]);
if(f.exists()){
Log.i("
SDCARD ","DITAMBAHKAN " + blocks[j]);
result.add(blocks[j]);
}
}catch(Exception e){
}
}
}
}
else
{
Log.d("
SDCARD ","Not an SDCard / External Storage" + lines[i]);
}
}
return result;
}
No comments:
Post a Comment