The following method is called when I click the save button. However, the data is still been stored in my internal storage and not the sd card(external storage). Am I using the wrong permissions, methods?
public void save(View v)
{
if(isExternalStorageWriteable() && checkPermission(andriod.Manifest.permission.WRITE_EXTERNAL_STORAGE)){
File textfile = new File(Environment.getExternalStorageDirectory(), "Device 1 ");
try{
FileOutputStream fos = new FileOutputStream(textfile);
fos.write(epc.toString().getBytes());
fos.close();
Log.i("State","2");
Toast.makeText(this, "File saved.", Toast.LENGTH_LONG).show();
}
catch (IOException e)
{
e.printStackTrace();
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
else
{
Log.i("State","4");
Toast.makeText(this, "File not saved.", Toast.LENGTH_LONG).show();
}
}
private boolean isExternalStorageWriteable()
{
if(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())){
Log.i("State","Yes, it is writeable!");
return true;
}
else{
return false;
}
}
public boolean checkPermission(String permission){
int check = ContextCompat.checkSelfPermission(this,permission);
return (check == PackageManager.PERMISSION_GRANTED);
}
Android Manifest
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>