Cleanup base directory selection, use Context.getExternalFilesDirs and request WRITE_EXTERNAL_STORAGE permission, use AndroidX and raise minSdkVersion to 14. Use File instead of plain Strings for paths in some places, use try-with-resources, and some other small improvements.
This commit is contained in:
parent
72e2e13d07
commit
dbdfd36f88
17 changed files with 173 additions and 220 deletions
|
|
@ -6,59 +6,35 @@ import java.io.InputStream;
|
|||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.File;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
public class ConfigHelper
|
||||
{
|
||||
public static String getBaseDir( Context ctx )
|
||||
public static File getBaseDir( Context ctx )
|
||||
{
|
||||
// get base dir from private file
|
||||
InputStream configInput = null;
|
||||
try
|
||||
{
|
||||
configInput = ctx.openFileInput( "config15.dat" );
|
||||
BufferedReader br = new BufferedReader( new InputStreamReader( configInput ) );
|
||||
return br.readLine();
|
||||
|
||||
try (InputStream configInput = ctx.openFileInput( "config15.dat" );
|
||||
InputStreamReader isr = new InputStreamReader( configInput );
|
||||
BufferedReader br = new BufferedReader(isr)) {
|
||||
return new File ( br.readLine() );
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if ( configInput != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
configInput.close();
|
||||
}
|
||||
catch (Exception ee)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeBaseDir( Context ctx, String baseDir )
|
||||
public static void writeBaseDir( Context ctx, File baseDir )
|
||||
{
|
||||
BufferedWriter bw = null;
|
||||
try
|
||||
{
|
||||
OutputStream configOutput = ctx.openFileOutput( "config15.dat", Context.MODE_PRIVATE );
|
||||
bw = new BufferedWriter( new OutputStreamWriter( configOutput ) );
|
||||
bw.write( baseDir );
|
||||
try (OutputStream configOutput = ctx.openFileOutput( "config15.dat", Context.MODE_PRIVATE );
|
||||
OutputStreamWriter osw = new OutputStreamWriter( configOutput );
|
||||
BufferedWriter bw = new BufferedWriter( osw)) {
|
||||
bw.write( baseDir.getAbsolutePath () );
|
||||
bw.write( '\n' );
|
||||
}
|
||||
catch (Exception e){ /* ignore */ }
|
||||
finally
|
||||
{
|
||||
if ( bw != null )
|
||||
try
|
||||
{
|
||||
bw.close();
|
||||
}
|
||||
catch (Exception ee) { /* ignore */ }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue