Changeset 1726 for trunk/autoquest-androidmonitor/src/de/ugoe/cs
- Timestamp:
- 09/05/14 10:44:54 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-androidmonitor/src/de/ugoe/cs/autoquest/androidmonitor/AndroidmonitorLogFile.java
r1725 r1726 2 2 3 3 import java.io.File; 4 import java.io.IOException; 5 import java.io.OutputStreamWriter; 4 import java.io.FileOutputStream; 6 5 import java.io.StringWriter; 7 6 8 7 import org.xmlpull.v1.XmlSerializer; 9 8 10 import android.app.Activity;11 import android.content.Context;12 9 import android.util.Log; 13 10 import android.util.Xml; 14 11 15 public class AndroidmonitorLogFile extends Activity{16 // extends activity to use the file handling methods of an activity 12 public class AndroidmonitorLogFile { 13 17 14 private String name; 18 15 16 public AndroidmonitorLogFile(String appName, File dir) { 17 this.name = "android_" + appName + "_LogFile.xml"; 19 18 20 public AndroidmonitorLogFile(String appName, File dir) {21 this.name = appName + "LogFile.xml";22 23 19 try { 20 // prove if file exists 24 21 File file = new File(dir, this.name); 25 if (!file.exists()) { 26 Log.d("file", this.name + " - is not available"); 27 28 //create file 22 /* 23 * if file does not exists write device and app information to a new 24 * file. Otherwise use existing file and add activity information to 25 * file. 26 */ 27 if (true) { //!file.exists() 28 /* 29 * create log file. Using method openFileOutput() does not work 30 * for this project due to the reason that this method would try 31 * to create the file in the directory of the non-existing 32 * directory de.ugoe.cs.androidmonitor. This directory does not 33 * exist due to the reason that this project is a library and 34 * the file has to be stored in the directory of the running 35 * application. Furthermore it would not be possible to write in 36 * another app directory as the own one. 37 */ 38 String string = getDeviceInformation() + getAppInformation(); 29 39 try { 30 OutputStreamWriter outputStreamWriter = new OutputStreamWriter( 31 openFileOutput(this.name, Context.MODE_PRIVATE)); 32 outputStreamWriter.write(getDeviceInformation() + getAppInformation()); 33 outputStreamWriter.close(); 34 } catch (IOException e) { 35 e.printStackTrace(); 36 Log.e("outputStreamWriter", e.getMessage()); 40 FileOutputStream outputStream = new FileOutputStream(file); 41 outputStream.write(string.getBytes()); 42 outputStream.close(); 43 } catch (Exception e) { 44 Log.e("file", "outputstream: " + e.getMessage()); 37 45 } 38 39 46 40 47 } 41 48 } catch (Exception e) { 42 49 e.printStackTrace(); 43 Log.e("file", e.getMessage());50 Log.e("file", "file: " + e.getMessage()); 44 51 } 45 52 … … 59 66 return ""; 60 67 } 61 62 private String getDeviceInformation(){ 63 String deviceInformation = null; 68 69 private String getDeviceInformation() { 70 String deviceInformation = ""; 71 XmlSerializer serializer = Xml.newSerializer(); 72 StringWriter writer = new StringWriter(); 64 73 try { 65 XmlSerializer xmlSerializer = Xml.newSerializer(); 66 StringWriter stringWriter = new StringWriter(); 74 serializer.setOutput(writer); 75 serializer.startDocument("UTF-8", true); 76 serializer.startTag("", "device"); 77 serializer.startTag("", "param"); 78 serializer.attribute("", "value", "" 79 + android.os.Build.VERSION.SDK_INT); 80 serializer.attribute("", "name", "sdk_version"); 81 serializer.endTag("", "param"); 82 83 serializer.startTag("", "param"); 84 serializer.attribute("", "value", android.os.Build.DEVICE); 85 serializer.attribute("", "name", "device"); 86 serializer.endTag("", "param"); 87 88 serializer.startTag("", "param"); 89 serializer.attribute("", "value", android.os.Build.MANUFACTURER); 90 serializer.attribute("", "name", "manufacturer"); 91 serializer.endTag("", "param"); 92 93 serializer.startTag("", "param"); 94 serializer.attribute("", "value", android.os.Build.MODEL); 95 serializer.attribute("", "name", "model"); 96 serializer.endTag("", "param"); 97 98 // tbd get resolution ... 99 100 serializer.endTag("", "device"); 101 serializer.endDocument(); 67 102 68 xmlSerializer.setOutput(stringWriter); 69 xmlSerializer.startDocument("UTF-8", true); 70 xmlSerializer.startTag("", "device"); 71 xmlSerializer.startTag("", "param"); 72 xmlSerializer.attribute("", "value", "" + android.os.Build.VERSION.SDK_INT); 73 xmlSerializer.attribute("", "name", "sdk_version"); 74 xmlSerializer.endTag("", "param"); 75 76 xmlSerializer.startTag("", "param"); 77 xmlSerializer.attribute("", "value", android.os.Build.DEVICE); 78 xmlSerializer.attribute("", "name", "device"); 79 xmlSerializer.endTag("", "param"); 80 81 xmlSerializer.startTag("", "param"); 82 xmlSerializer.attribute("", "value", android.os.Build.MANUFACTURER); 83 xmlSerializer.attribute("", "name", "manufacturer"); 84 xmlSerializer.endTag("", "param"); 85 86 xmlSerializer.startTag("", "param"); 87 xmlSerializer.attribute("", "value", android.os.Build.MODEL); 88 xmlSerializer.attribute("", "name", "model"); 89 xmlSerializer.endTag("", "param"); 90 91 //tbd get resolution ... 92 93 94 xmlSerializer.endTag("", "device"); 95 deviceInformation = stringWriter.toString(); 96 103 deviceInformation = writer.toString(); 104 97 105 } catch (Exception e) { 98 e.printStackTrace(); 99 Log.e("xmlSerializer", e.getMessage()); 106 Log.e("xml", e.getMessage()); 100 107 } 101 108 102 109 return deviceInformation; 103 110 } 104 111 105 public void addComponent() {106 // add component to file112 public void addComponent() { 113 // add component to file 107 114 } 108 109 public void addEvent() {110 // add event to file115 116 public void addEvent() { 117 // add event to file 111 118 } 112 119 113 120 }
Note: See TracChangeset
for help on using the changeset viewer.