Added a check so we dont try to write to sdcard if its unavailable
This commit is contained in:
parent
666494f4dd
commit
b266a711e7
1 changed files with 16 additions and 3 deletions
|
|
@ -8,6 +8,7 @@ import android.net.NetworkInfo;
|
|||
import android.net.Uri;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Environment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.telephony.gsm.GsmCellLocation;
|
||||
|
|
@ -43,7 +44,7 @@ public class CSVWriter {
|
|||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
comment = "";
|
||||
|
||||
String path = prefs.getString("logging_path", "/sdcard/uecontrol/");
|
||||
String path = prefs.getString("logging_path", Environment.getExternalStorageDirectory().getAbsolutePath()+"/uecontrol/");
|
||||
if(!path.endsWith(File.separator)) path += File.separator;
|
||||
file = new File(
|
||||
path,
|
||||
|
|
@ -62,6 +63,9 @@ public class CSVWriter {
|
|||
new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
|
||||
}
|
||||
|
||||
public void addComment(String str){
|
||||
comment = str;
|
||||
}
|
||||
|
||||
public void write(String behaviour, double down, double up){
|
||||
StringBuilder line = new StringBuilder();
|
||||
|
|
@ -80,6 +84,8 @@ public class CSVWriter {
|
|||
}
|
||||
|
||||
protected void writeLine(String line){
|
||||
if(!isExternalStorageWritable())
|
||||
return;
|
||||
try{
|
||||
PrintWriter out = new PrintWriter(new FileOutputStream(file, true));
|
||||
out.println(line);
|
||||
|
|
@ -89,10 +95,17 @@ public class CSVWriter {
|
|||
}
|
||||
}
|
||||
|
||||
public void addComment(String str){
|
||||
comment = str;
|
||||
/* Checks if external storage is available for read and write */
|
||||
private boolean isExternalStorageWritable() {
|
||||
String state = Environment.getExternalStorageState();
|
||||
if (Environment.MEDIA_MOUNTED.equals(state)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//******************* INFORMATION FUNCTIONS ********************************************
|
||||
public static String getRat(){
|
||||
Context context = MainActivity.getContext();
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue