Añadido boton de guardado y comienzo de interfaz de guardado en archivo físico
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package com.journaldev.gpslocationtracking;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class FIleManager {
|
||||
|
||||
|
||||
public void writeToFile(String data, Context context) {
|
||||
try {
|
||||
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(context.openFileOutput("coordenadas.txt", Context.MODE_PRIVATE));
|
||||
outputStreamWriter.write(data);
|
||||
outputStreamWriter.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
Log.e("Exception", "File write failed: " + e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private String readFromFile(Context context) {
|
||||
|
||||
String ret = "";
|
||||
|
||||
try {
|
||||
InputStream inputStream = context.openFileInput("coordenadas.txt");
|
||||
|
||||
if ( inputStream != null ) {
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
|
||||
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
|
||||
String receiveString = "";
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
while ( (receiveString = bufferedReader.readLine()) != null ) {
|
||||
stringBuilder.append("\n").append(receiveString);
|
||||
}
|
||||
|
||||
inputStream.close();
|
||||
ret = stringBuilder.toString();
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
Log.e("login activity", "File not found: " + e.toString());
|
||||
} catch (IOException e) {
|
||||
Log.e("login activity", "Can not read file: " + e.toString());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,13 @@
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context="com.journaldev.gpslocationtracking.MainActivity">
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/btn2"
|
||||
android:text="Save Data"
|
||||
android:layout_centerHorizontal="true" android:layout_alignParentBottom="true"
|
||||
android:layout_marginBottom="153dp"/>
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
Reference in New Issue
Block a user