Android Open Source - Android-Universal-Notifier Logger






From Project

Back to project page Android-Universal-Notifier.

License

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.

Java Source Code

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);
  }
}




Java Source Code List

com.mairos.universalnotifier.UI.LogFragmentTab.java
com.mairos.universalnotifier.UI.MainActivity.java
com.mairos.universalnotifier.UI.SettingsActivity.java
com.mairos.universalnotifier.UI.TabListener.java
com.mairos.universalnotifier.UI.TaskInfoActivity.java
com.mairos.universalnotifier.UI.TasksFragmentTab.java
com.mairos.universalnotifier.model.AlarmManagerBroadcastReceiver.java
com.mairos.universalnotifier.model.AttachmentData.java
com.mairos.universalnotifier.model.Const.java
com.mairos.universalnotifier.model.JSInterpreter.java
com.mairos.universalnotifier.model.LauncherBroadcastReceiver.java
com.mairos.universalnotifier.model.Logger.java
com.mairos.universalnotifier.model.NotificationService.java
com.mairos.universalnotifier.model.NotificationTask.java
com.mairos.universalnotifier.model.TasksQueue.java
com.mairos.universalnotifier.model.TasksXMLLoader.java
com.mairos.universalnotifier.network.GMailSender.java
com.mairos.universalnotifier.network.JSSEProvider.java
com.mairos.universalnotifier.network.NetworkOperations.java
com.mairos.universalnotifier.network.SMSSender.java