- Home /
Java - Android - Accessing the /data/data folder
I'm writing an application to get a person's ID from a game and it is stored in
/data/data/AppName/shared_prefs/AppName.xml
I was writing a method to access the PlayerPrefs but it according to my program the file doesn't exist.
private void AccessPlayerPrefs() //TODO: Refactor this method.
{
File externalStorage = Environment.getExternalStorageDirectory();
File internalStorage = Environment.getDataDirectory();
if(externalStorage.canWrite())
{
String currentDBPath = "/data/com.outerminds.tubular/shared_prefs/com.outerminds.tubular.xml"; //
String backupDBPath = "/Video/appname_backup.xml";
File currentDB = new File(internalStorage, currentDBPath);
File backupDB = new File(externalStorage, backupDBPath);
if (currentDB.exists())
{
try
{
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
}
catch (Exception e)
{
AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
builder.setMessage(e.getMessage()).setNegativeButton("Okay", null).create().show();
}
}
else
{
AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
builder.setMessage("It doesn't exist.").setNegativeButton("Okay", null).create().show();
}
}
else
{
AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
builder.setMessage("Can't write").setNegativeButton("Okay", null).create().show();
}
}
Could anyone help me resolve this issue.
Comment
Your answer
Follow this Question
Related Questions
Getting String from Java Class on Android 0 Answers
Error building with custom java code [Solved] 1 Answer
Multiple Cars not working 1 Answer