Browse Source

Fix force close

tags/SensorLogger/0.2.2
Chris Smith 14 years ago
parent
commit
ff89f3b4d6

+ 2
- 1
code/SensorLogger/AndroidManifest.xml View File

@@ -1,6 +1,6 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
-     package="uk.co.md87.android.sensorlogger" android:versionCode="14" android:versionName="0.2.1">
3
+     package="uk.co.md87.android.sensorlogger" android:versionCode="15" android:versionName="0.2.2">
4 4
     <application android:label="Sensor Logger" android:icon="@drawable/icon">
5 5
         <activity android:name=".activities.IntroActivity" android:label="Sensor Logger">
6 6
             <intent-filter>
@@ -31,6 +31,7 @@
31 31
 
32 32
     <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
33 33
     <uses-permission android:name="android.permission.INTERNET"/>
34
+    <uses-permission android:name="android.permission.VIBRATE"/>
34 35
 
35 36
     <uses-sdk android:minSdkVersion="3" />
36 37
 </manifest>

BIN
code/SensorLogger/dist/SensorLogger.apk View File


+ 76
- 0
code/SensorLogger/src/uk/co/md87/android/sensorlogger/ExceptionHandler.java View File

@@ -0,0 +1,76 @@
1
+/*
2
+ * To change this template, choose Tools | Templates
3
+ * and open the template in the editor.
4
+ */
5
+
6
+package uk.co.md87.android.sensorlogger;
7
+
8
+import java.io.IOException;
9
+import java.io.PrintWriter;
10
+import java.io.StringWriter;
11
+import java.io.Writer;
12
+import java.lang.Thread.UncaughtExceptionHandler;
13
+import java.util.ArrayList;
14
+import java.util.List;
15
+import org.apache.http.NameValuePair;
16
+import org.apache.http.client.entity.UrlEncodedFormEntity;
17
+import org.apache.http.client.methods.HttpPost;
18
+import org.apache.http.impl.client.DefaultHttpClient;
19
+import org.apache.http.message.BasicNameValuePair;
20
+import org.apache.http.protocol.HTTP;
21
+
22
+/**
23
+ *
24
+ * @author chris
25
+ */
26
+public class ExceptionHandler implements UncaughtExceptionHandler {
27
+
28
+    private UncaughtExceptionHandler defaultUEH;
29
+
30
+    private String url, version, imei;
31
+
32
+    /*
33
+     * if any of the parameters is null, the respective functionality
34
+     * will not be used
35
+     */
36
+    public ExceptionHandler(String url, String version, String imei) {
37
+        this.url = url;
38
+        this.version = version;
39
+        this.imei = imei;
40
+        this.defaultUEH = Thread.getDefaultUncaughtExceptionHandler();
41
+    }
42
+
43
+    public void uncaughtException(Thread t, Throwable e) {
44
+        String timestamp = String.valueOf(System.currentTimeMillis());
45
+        final Writer result = new StringWriter();
46
+        final PrintWriter printWriter = new PrintWriter(result);
47
+        e.printStackTrace(printWriter);
48
+        String stacktrace = result.toString();
49
+        printWriter.close();
50
+        String filename = timestamp + ".stacktrace";
51
+
52
+        sendToServer(stacktrace, filename);
53
+
54
+        defaultUEH.uncaughtException(t, e);
55
+    }
56
+
57
+    private void sendToServer(String stacktrace, String filename) {
58
+        DefaultHttpClient httpClient = new DefaultHttpClient();
59
+        HttpPost httpPost = new HttpPost(url);
60
+
61
+        httpPost.setHeader("x-application", "SensorLogger-exception");
62
+        httpPost.setHeader("x-version", version);
63
+        httpPost.setHeader("x-imei", imei);
64
+
65
+        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
66
+        nvps.add(new BasicNameValuePair("filename", filename));
67
+        nvps.add(new BasicNameValuePair("stacktrace", stacktrace));
68
+        try {
69
+            httpPost.setEntity(
70
+                    new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
71
+            httpClient.execute(httpPost);
72
+        } catch (IOException e) {
73
+            e.printStackTrace();
74
+        }
75
+    }
76
+}

+ 19
- 0
code/SensorLogger/src/uk/co/md87/android/sensorlogger/activities/IntroActivity.java View File

@@ -6,12 +6,15 @@
6 6
 package uk.co.md87.android.sensorlogger.activities;
7 7
 
8 8
 import android.content.Intent;
9
+import android.content.pm.PackageManager.NameNotFoundException;
9 10
 import android.os.Bundle;
10 11
 import android.os.RemoteException;
12
+import android.telephony.TelephonyManager;
11 13
 import android.util.Log;
12 14
 import android.view.View;
13 15
 import android.view.View.OnClickListener;
14 16
 import android.widget.Button;
17
+import uk.co.md87.android.sensorlogger.ExceptionHandler;
15 18
 
16 19
 import uk.co.md87.android.sensorlogger.R;
17 20
 
@@ -26,11 +29,27 @@ public class IntroActivity extends BoundActivity implements OnClickListener {
26 29
     public void onCreate(final Bundle icicle) {
27 30
         super.onCreate(icicle);
28 31
 
32
+        Thread.setDefaultUncaughtExceptionHandler(
33
+                new ExceptionHandler("http://chris.smith.name/android/upload",
34
+                getVersionName(), getIMEI()));
35
+
29 36
         setContentView(R.layout.intro);
30 37
 
31 38
         ((Button) findViewById(R.id.introstart)).setOnClickListener(this);
32 39
     }
33 40
 
41
+    public String getVersionName() {
42
+        try {
43
+            return getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
44
+        } catch (NameNotFoundException ex) {
45
+            return "Unknown";
46
+        }
47
+    }
48
+
49
+    public String getIMEI() {
50
+        return ((TelephonyManager) getSystemService(TELEPHONY_SERVICE)).getDeviceId();
51
+    }
52
+
34 53
     /** {@inheritDoc} */
35 54
     @Override
36 55
     public void onClick(final View arg0) {

+ 1
- 0
website/index.html View File

@@ -45,6 +45,7 @@
45 45
       <p>The application provides a link to a web-based portal where users can see a graph of their uploaded data, and the results of the activity detection algorithm will also be surfaced there.</p>
46 46
       <h4>Changelog</h4>
47 47
       <ul>
48
+       <li><strong>0.2.1 &rarr; 0.2.2</strong>: Fix force close, add reporting of exceptions</li>
48 49
        <li><strong>0.2.0 &rarr; 0.2.1</strong>: Bug fix related to turning display off</li>
49 50
        <li><strong>0.1.6 &rarr; 0.2.0</strong>: Near-complete rewrite: much improved UI, classification on device, bug fixes</li>
50 51
        <li><strong>0.1.5 &rarr; 0.1.6</strong>: Fix force close on devices that use MEIDs not IMEI numbers</li>

Loading…
Cancel
Save