Add MailUtil and send log mail
[rtmpclient.git] / app / src / main / java / ai / suanzi / rtmpclient / LogUtil.java
1 package ai.suanzi.rtmpclient;
2
3 import android.content.Intent;
4
5 import org.apache.log4j.Level;
6 import org.apache.log4j.Logger;
7 import de.mindpipe.android.logging.log4j.LogConfigurator;
8 import java.util.Properties;
9 import javax.mail.Transport;
10 import javax.mail.Session;
11 import javax.mail.internet.MimeMessage;
12 import javax.mail.internet.InternetAddress;
13 import java.util.Date;
14 import android.os.StrictMode;
15
16 import java.io.File;
17
18 public class LogUtil {
19
20     private static Logger gLogger;
21     private static final String FILE_NAME = "log.txt";
22     private static final long MAX_SIZE = 1024 * 1024 * 10; // 10M
23     private static String logFile = "";
24
25
26     public static void config(File dir) {
27         try {
28             final LogConfigurator logConfigurator = new LogConfigurator();
29             //String fname = getExternalFilesDir(null) + File.separator + "log.txt";
30             logFile = dir + File.separator + FILE_NAME;
31             logConfigurator.setFileName(logFile);
32             logConfigurator.setRootLevel(Level.DEBUG);
33             logConfigurator.setLevel("org.apache", Level.ERROR);
34             logConfigurator.setMaxFileSize(MAX_SIZE);
35             logConfigurator.configure();
36             gLogger = Logger.getLogger("LogUtil");
37             gLogger.error("#######################################");
38             gLogger.debug("Log file is located at: " + logFile);
39
40         } catch (Exception e){
41             e.printStackTrace();
42         }
43         try {
44
45
46             int SDK_INT = android.os.Build.VERSION.SDK_INT;
47             if (SDK_INT > 8)
48             {
49                 StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
50                         .permitAll().build();
51                 StrictMode.setThreadPolicy(policy);
52                 //your codes here
53                 MailUtil.sendMail();
54
55
56             }
57         } catch (Exception e) {
58             e.printStackTrace();
59         }
60     }
61
62
63
64
65 }
66
67
68 //
69 //
70 //    public void sendEmail()
71 //    {
72 //
73 //        private static final int PICK_FROM_GALLERY = 101;
74 //        int columnIndex;
75 //        try
76 //        {
77 //
78 //
79 //
80 //            final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
81 //            emailIntent.setType("plain/text");
82 //            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { "Email" });
83 //            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
84 //            if (URI != null) {
85 //                emailIntent.putExtra(Intent.EXTRA_STREAM, URI);
86 //            }
87 //            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "This is a message");
88 //            this.startActivity(Intent.createChooser(emailIntent,"Sending email..."));
89 //        }
90 //        catch (Throwable t)
91 //        {
92 //            Toast.makeText(this, "Request failed try again: " + t.toString(),Toast.LENGTH_LONG).show();
93 //        }
94 //    }
95 //    public void openFolder()
96 //    {
97 //        Intent intent = new Intent();
98 //        intent.setType("image/*");
99 //        intent.setAction(Intent.ACTION_GET_CONTENT);
100 //        intent.putExtra("return-data", true);
101 //        startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_GALLERY);
102 //    }
103 //
104 //    public static sendLogs(){
105 //
106 //    }
107 //
108 //    public void SendLoagcatMail(){
109 //
110 //        // save logcat in file
111 //        /*File outputFile = new File(Environment.getExternalStorageDirectory(),
112 //                "logcat.txt");
113 //        try {
114 //            Runtime.getRuntime().exec(
115 //                    "logcat -f " + outputFile.getAbsolutePath());
116 //        } catch (IOException e) {
117 //            // TODO Auto-generated catch block
118 //            e.printStackTrace();
119 //        }*/
120 //        String fname = getExternalFilesDir(null) + File.separator + "log.txt";
121 //
122 //        File logfile = new File(fname);
123 //
124 //        //send file using email
125 //        Intent emailIntent = new Intent(Intent.ACTION_SEND);
126 //        emailIntent.setType("vnd.android.cursor.dir/email");
127 //        String to[] = {"seudut@gmail.com"};
128 //        emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
129 //        // the attachment
130 //        emailIntent.putExtra(Intent.EXTRA_STREAM, logfile.getAbsolutePath());
131 //        // the mail subject
132 //        emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
133 //        startActivity(Intent.createChooser(emailIntent , "Send email..."));
134 //    }
135
136 //}