</activity>
<activity
android:name=".CampusAppCrashHandler"
- android:theme="@android:style/Theme.Dialog"
- android:textAppearance="@android:style/TextAppearance.Large"
+ android:theme="@style/AppTheme"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="de.dhbw.campusapp.CRASH_LOG" />
AppContext = new CampusAppContext(this, R.id.fragment_container, R.id.nav_view);
else
AppContext.setMainActivity(this);
-
+
super.onResume();
Log.i("CampusApp", "onResume event");
AppContext.getNfcCardListener().resumeForefrontDispatcher();
import android.app.Activity;
import android.os.Bundle;
+import android.view.View;
import android.view.Window;
+import android.webkit.WebView;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.ProgressBar;
/**
* Created by pk910 on 11.03.2016.
*/
public class CampusAppCrashHandler extends Activity {
+ private static boolean crashLogWindowOpened = false;
+ private static final Object crashWindowLock = new Object();
+
+ private String crashdate, stacktrace;
+ private CampusAppExceptionHandler exceptionHandler;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_NO_TITLE); // make a dialog without a titlebar
+
+ synchronized (crashWindowLock) {
+ if(crashLogWindowOpened) {
+ int p = android.os.Process.myPid();
+ android.os.Process.killProcess(p);
+ return;
+ }
+ crashLogWindowOpened = true;
+ }
+
+ requestWindowFeature(Window.FEATURE_NO_TITLE); // make a window without a titlebar
setContentView(R.layout.crash_log);
+ final Activity that = this;
+
+ Bundle extras = getIntent().getExtras();
+ crashdate = (extras != null ? extras.getString("crashdate") : null);
+
+ EditText crashLog = (EditText) findViewById(R.id.crashLog);
+ exceptionHandler = new CampusAppExceptionHandler();
+ stacktrace = exceptionHandler.getCrashStacktrace(that, crashdate);
+ crashLog.setText(stacktrace);
+
+ Button sendButton = (Button) findViewById(R.id.sendCrashLog);
+ sendButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Button sendButton = (Button) v;
+ ProgressBar sendProgress = (ProgressBar) findViewById(R.id.sendProgressBar);
+
+
+ sendButton.setEnabled(false);
+ sendProgress.setVisibility(View.VISIBLE);
+
- Bundle extras = this.getIntent().getExtras();
- String crashdate = (extras != null ? extras.getString("crashdate") : null);
+ exceptionHandler.postprocessException(crashdate, stacktrace, new CampusAppExceptionHandler.PostProcessingCallback() {
+ @Override
+ public void onPostProcessFinished(String response) {
+ ProgressBar sendProgress = (ProgressBar) findViewById(R.id.sendProgressBar);
+ WebView reportResponse = (WebView) findViewById(R.id.crashReportResponse);
- CampusAppExceptionHandler exceptionHandler = new CampusAppExceptionHandler();
- exceptionHandler.postprocessException(this, crashdate);
+ sendProgress.setVisibility(View.GONE);
+ reportResponse.setVisibility(View.VISIBLE);
+ reportResponse.loadData(response, "text/html", null);
+ }
+ });
+ }
+ });
}
}
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));
}
});
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
- <RelativeLayout
- android:layout_width="250dp"
+ <android.support.design.widget.AppBarLayout
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_gravity="center_horizontal">
-
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textAppearance="?android:attr/textAppearanceLarge"
- android:text="Irgendwas Doofes ist passiert. :/"
- android:id="@+id/textView38"
- android:layout_gravity="center_horizontal" />
-
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:text="Crash Stacktrace wird an Entwickler gesendet..."
- android:id="@+id/textView39"
+ android:theme="@style/AppTheme.AppBarOverlay">
+ <android.support.v7.widget.Toolbar
+ android:id="@+id/toolbar"
+ android:layout_width="match_parent"
+ android:layout_height="?attr/actionBarSize"
+ android:background="?attr/colorPrimary"
+ app:popupTheme="@style/AppTheme.PopupOverlay">
+
+ <LinearLayout
+ android:id="@+id/title_container"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="center_vertical"
+ android:orientation="horizontal"
+ android:visibility="visible">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceLarge"
+ android:text="@string/app_name"
+ android:layout_weight="1"
+ android:id="@+id/title" />
+
+ </LinearLayout>
+
+ </android.support.v7.widget.Toolbar>
+ </android.support.design.widget.AppBarLayout>
+
+ <LinearLayout
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <ImageView
+ android:layout_width="match_parent"
+ android:layout_height="100dp"
+ android:id="@+id/imageView4"
android:layout_gravity="center_horizontal"
- android:layout_below="@+id/textView38" />
- </RelativeLayout>
+ android:src="@drawable/android_crash"
+ android:background="#ffffff"
+ android:paddingTop="8dp"
+ android:paddingBottom="8dp" />
+
+ <LinearLayout
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_marginLeft="8dp"
+ android:layout_marginRight="8dp">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceLarge"
+ android:text="Sorry, Irgendwas Doofes ist passiert."
+ android:id="@+id/textView38" />
+
+ <RelativeLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:layout_marginTop="8dp">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Crash Log:"
+ android:id="@+id/textView39" />
+
+ <ScrollView
+ android:layout_width="fill_parent"
+ android:layout_height="200dp"
+ android:id="@+id/scrollView6"
+ android:layout_below="@+id/textView39"
+ android:background="#ffffff">
+
+ <EditText
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:padding="2dp"
+ android:background="#FFF"
+ android:textSize="10dp"
+ android:layout_below="@+id/textView39"
+ android:typeface="monospace"
+ android:id="@+id/crashLog" />
+ </ScrollView>
+
+ <ProgressBar
+ style="?android:attr/progressBarStyleLarge"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:id="@+id/sendProgressBar"
+ android:layout_centerVertical="true"
+ android:layout_centerHorizontal="true"
+ android:visibility="gone" />
+
+ </RelativeLayout>
+
+ <Button
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Crash Log an Entwickler senden"
+ android:id="@+id/sendCrashLog"
+ android:layout_gravity="center_horizontal"
+ android:layout_marginTop="4dp" />
+
+ <WebView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:id="@+id/crashReportResponse"
+ android:layout_gravity="center_horizontal"
+ android:visibility="gone" />
+
+ </LinearLayout>
+
+ </LinearLayout>
</LinearLayout>
\ No newline at end of file