Is there any way to know(programmatically) in your Activity/Application that the user has connected your phone to PC through USB?
If all you want to do is detect whether you have access to the sdcard, then the following will work:
private boolean canWriteToFlash() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return true;
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
// Read only isn't good enough
return false;
} else {
return false;
}
}