import java.util.List;
import cz.msebera.android.httpclient.Header;
-import cz.msebera.android.httpclient.NameValuePair;
-import cz.msebera.android.httpclient.client.entity.UrlEncodedFormEntity;
-import cz.msebera.android.httpclient.client.methods.HttpPost;
-import cz.msebera.android.httpclient.impl.client.DefaultHttpClient;
-import cz.msebera.android.httpclient.message.BasicNameValuePair;
-import cz.msebera.android.httpclient.protocol.HTTP;
/**
* Created by pk910 on 11.03.2016.
private String localPath;
private static boolean crashLogWindowOpened = false;
+ private static final Object crashWindowLock = new Object();
public void handleUncaughtException(Thread thread, Throwable e) {
// automatically send crash log to my server for debuggging.
// disable this for productive use! (CampusAppContext.DEBUG)
+ synchronized (crashWindowLock) {
+ if(crashLogWindowOpened)
+ return;
+ crashLogWindowOpened = true;
+ }
+
final Writer result = new StringWriter();
final PrintWriter printWriter = new PrintWriter(result);
e.printStackTrace(printWriter);
writeToFile(stacktrace, filename);
// start crash screen
- if(!crashLogWindowOpened) {
- try {
- Intent intent = new Intent();
- intent.setAction("de.dhbw.campusapp.CRASH_LOG");
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // required when starting from Application
- intent.putExtra("crashdate", crashdate);
- mainActivity.startActivity(intent);
- crashLogWindowOpened = true;
- } catch (Exception ex) {
- }
+ try {
+ Intent intent = new Intent();
+ intent.setAction("de.dhbw.campusapp.CRASH_LOG");
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // required when starting from Application
+ intent.putExtra("crashdate", crashdate);
+ mainActivity.startActivity(intent);
+ } catch (Exception ex) {
}
}
}
}
- public void postprocessException(Activity crashLogScreen, String crashdate) {
+
+ public interface PostProcessingCallback {
+ public void onPostProcessFinished(String response);
+ }
+
+ public String getCrashStacktrace(Activity crashLogScreen, String crashdate) {
localPath = crashLogScreen.getApplicationContext().getFilesDir().getAbsolutePath();
String fileName = localPath + "/" + crashdate + ".stacktrace";
StringBuilder stackTrace = new StringBuilder();
catch (IOException e) {
//You'll need to add proper error handling here
}
+ return stackTrace.toString();
+ }
- sendToServer(CRASHLOG_UPLOAD, stackTrace.toString(), crashdate);
+ public void postprocessException(String crashdate, String stacktrace, PostProcessingCallback callback) {
+ sendToServer(CRASHLOG_UPLOAD, stacktrace, crashdate, callback);
}
- private void sendToServer(String url, String stacktrace, String crashdate) {
+ private void sendToServer(String url, String stacktrace, String crashdate, final PostProcessingCallback callback) {
AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();
params.add("stacktrace", stacktrace);
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
- Log.i("CrashLog", "OK: "+(responseBody != null ? new String(responseBody) : null));
+ callback.onPostProcessFinished((responseBody != null ? new String(responseBody) : null));
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
- Log.i("CrashLog", "Failed: "+(responseBody != null ? new String(responseBody) : null));
+ callback.onPostProcessFinished("Failed: "+(responseBody != null ? new String(responseBody) : null));
}
});
}