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:
Niklas Guertler 2020-05-24 17:49:50 +02:00
parent 72e2e13d07
commit dbdfd36f88
17 changed files with 173 additions and 220 deletions

View file

@ -11,6 +11,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
import java.util.zip.GZIPOutputStream;
import java.util.ArrayList;
@ -58,7 +59,7 @@ public class BRouterService extends Service
if ( configInput != null ) try { configInput.close(); } catch (Exception ee) {}
}
worker.baseDir = baseDir;
worker.segmentDir = baseDir + "/brouter/segments4";
worker.segmentDir = new File (baseDir, "brouter/segments4" );
String remoteProfile = params.getString( "remoteProfile" );
@ -85,9 +86,9 @@ public class BRouterService extends Service
try
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.write( "z64".getBytes("UTF-8") ); // marker prefix
baos.write( "z64".getBytes(StandardCharsets.UTF_8) ); // marker prefix
OutputStream os = new GZIPOutputStream( baos );
byte[] ab = gpxMessage.getBytes("UTF-8");
byte[] ab = gpxMessage.getBytes(StandardCharsets.UTF_8);
gpxMessage = null;
os.write( ab );
ab = null;