janggirl
janggirl

Reputation: 11

How to detect external sdcard using command lines

I am writing a script using perl to detect whether the device has the external sd card or not. I understand there is Android API Environment to check, but I am not able to import any APIs.

Currently, I found that there are /storage/sdcard0 (internal) and /storage/sdcard1 (external).

First question is, what is difference between /sdcard/ and /storage/sdcard0. They seem to point at the same thing.

Second question is, how can I write a script to detect the external sdcard? Even if the sdcard is not inserted, the path to the directory sdcard1 still exists. It is just empty when the sdcard is not inserted. I can get the capacity of sdcard by running command 'df storage/sdcard1' However, it takes much work to parse the capacity number and check the size. The device is currently running 4.3 and it doesnt have any /mnt/extSDcard or anything points to the external sdcard. It would be lot easier if storage/sdcard1 did not exist when the sdcard is not inserted, but since it still exists, it gets really tricky...

I am wondering if there is any easier way or any command line which it returns true/false if the sdcard is inserted or not..

Thanks

Upvotes: 0

Views: 1346

Answers (1)

user2362610
user2362610

Reputation: 1

i think this is a bit too late, but i ran into the very same problem. this is what i'm doing now, but not confirmed working yet.

in short it is using df on the external sdcard to check its size. if it's empty then it will be 0.00K. trim the result with tail and extract the size part with awk.

busybox required of course. in my device it is /storage/external_SD, you may need to change it.

df /storage/external_SD | busybox tail -n +2 | busybox awk '{print $2}'

Upvotes: 0

Related Questions