made acra catch and report errors

This commit is contained in:
Christian Schabesberger 2016-09-13 23:24:49 +02:00
parent 27bc414616
commit af2cddee91
3 changed files with 27 additions and 8 deletions

View File

@ -31,13 +31,8 @@ public class AcraReportSender implements ReportSender {
@Override
public void send(Context context, CrashReportData report) throws ReportSenderException {
Log.e("Newpipe UI ERROR", report.toString());
try {
((String)null).length();
} catch(Exception e) {
ErrorActivity.reportError(context, e, null, null,
ErrorActivity.ErrorInfo.make(ErrorActivity.SEARCHED,"none",
"App crash, UI failure", R.string.app_ui_crash));
}
ErrorActivity.reportError(context, report,
ErrorActivity.ErrorInfo.make(ErrorActivity.UI_ERROR,"none",
"App crash, UI failure", R.string.app_ui_crash));
}
}

View File

@ -26,6 +26,8 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import org.acra.ReportField;
import org.acra.collector.CrashReportData;
import org.json.JSONArray;
import org.json.JSONObject;
import org.schabi.newpipe.extractor.Parser;
@ -124,6 +126,7 @@ public class ErrorActivity extends AppCompatActivity {
public static final int SOMETHING_ELSE = 3;
public static final int USER_REPORT = 4;
public static final int LOAD_IMAGE = 5;
public static final int UI_ERROR = 6;
// MESSAGE STRING
public static final String SEARCHED_STRING = "searched";
@ -132,6 +135,7 @@ public class ErrorActivity extends AppCompatActivity {
public static final String SOMETHING_ELSE_STRING = "something";
public static final String USER_REPORT_STRING = "user report";
public static final String LOAD_IMAGE_STRING = "load image";
public static final String UI_ERROR_STRING = "ui error";
public static final String ERROR_EMAIL_ADDRESS = "crashreport@newpipe.schabi.org";
@ -211,6 +215,22 @@ public class ErrorActivity extends AppCompatActivity {
});
}
public static void reportError(final Context context, final CrashReportData report, final ErrorInfo errorInfo) {
// get key first (don't ask about this solution)
ReportField key = null;
for(ReportField k : report.keySet()) {
if(k.toString().equals("STACK_TRACE")) {
key = k;
}
}
String[] el = new String[] { report.get(key) };
Intent intent = new Intent(context, ErrorActivity.class);
intent.putExtra(ERROR_INFO, errorInfo);
intent.putExtra(ERROR_LIST, el);
context.startActivity(intent);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -397,6 +417,8 @@ public class ErrorActivity extends AppCompatActivity {
return USER_REPORT_STRING;
case LOAD_IMAGE:
return LOAD_IMAGE_STRING;
case UI_ERROR:
return UI_ERROR_STRING;
default:
return "Your description is in another castle.";
}

View File

@ -44,6 +44,8 @@ public class MainActivity extends AppCompatActivity {
setVolumeControlStream(AudioManager.STREAM_MUSIC);
mainFragment = getSupportFragmentManager()
.findFragmentById(R.id.search_fragment);
((String)null).length();
}
public boolean onCreateOptionsMenu(Menu menu) {