Each Android-perfect gadget bolsters a common "outer stockpiling or External Storage" that you can use to spare records. This can be a removable stockpiling media(Storage media), (for example, a SD card) or an inward (non-removable) capacity. Records spared to the outer stockpiling are world-intelligible and can be changed by the client when they empower USB mass stockpiling to exchange documents(transfer files) on a PC.
Access to external storage i.e Read or Write files.
In Android manifest.xml we have to include the code.
<manifest>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
<uses-permission android : name ="android.permission.WRITE_EXTERNAL_STORAGE/>
<uses-permission android : name ="android.permission.READ_EXTERNAL_STORAGE/>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
</manifest>
In MainActivity.java we have to write code for external storage below shown how it is,
//WRITE FILE //
public boolean isExternalStorageWritable() {
String externalstate = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(externalstate)) {
return true;
}
return false;
}
//READ FILE //
public boolean isExternalStorageReadable() {
String externalstate = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(externalstate) ||
Environment.MEDIA_MOUNTED_READ_ONLY.equals(externalstate)) {
return true;
}
return false;
}
Access to external storage i.e Read or Write files.
In Android manifest.xml we have to include the code.
<manifest>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
<uses-permission android : name ="android.permission.WRITE_EXTERNAL_STORAGE/>
<uses-permission android : name ="android.permission.READ_EXTERNAL_STORAGE/>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
</manifest>
In MainActivity.java we have to write code for external storage below shown how it is,
//WRITE FILE //
public boolean isExternalStorageWritable() {
String externalstate = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(externalstate)) {
return true;
}
return false;
}
//READ FILE //
public boolean isExternalStorageReadable() {
String externalstate = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(externalstate) ||
Environment.MEDIA_MOUNTED_READ_ONLY.equals(externalstate)) {
return true;
}
return false;
}
No comments:
Post a Comment