Back to project page Android-Universal-Notifier.
The source code is released under:
Apache License
If you think the Android project Android-Universal-Notifier listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.mairos.universalnotifier.model; //from w w w . j av a 2s . c om import java.io.FileOutputStream; import java.io.FileWriter; import java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.preference.PreferenceManager; public class Logger { private static final String logFile = "/log.txt"; public static void appendToLogFile(String f_txt, Context f_context){ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(f_context); String folder = prefs.getString("tasks_folder", "default"); FileOutputStream fos ; try { fos = new FileOutputStream(folder+logFile, true); FileWriter fWriter = null; try { StringBuilder msgStr = new StringBuilder(); Format formatter = new SimpleDateFormat("hh:mm:ss", Locale.US); msgStr.append(formatter.format(new Date())); fWriter = new FileWriter(fos.getFD()); fWriter.write(msgStr + ": " + f_txt + "\n"); fWriter.close(); } catch (Exception e) { e.printStackTrace(); } finally { fos.getFD().sync(); fos.close(); } } catch (Exception e) { e.printStackTrace(); } } public static void addToLog(String f_txt, Context f_context){ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(f_context); if (prefs.getBoolean("write_log", false)) appendToLogFile(f_txt, f_context); StringBuilder msgStr = new StringBuilder(); Format formatter = new SimpleDateFormat("hh:mm:ss", Locale.US); msgStr.append(formatter.format(new Date())); Intent intentCT = new Intent(); intentCT.setAction(Const.ACTION_ADD_TO_LOG); intentCT.putExtra(Const.TF_MESSAGE, msgStr + ": " + f_txt); f_context.sendBroadcast(intentCT); } }