本文整理汇总了Java中org.acra.collector.CrashReportData类的典型用法代码示例。如果您正苦于以下问题:Java CrashReportData类的具体用法?Java CrashReportData怎么用?Java CrashReportData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CrashReportData类属于org.acra.collector包,在下文中一共展示了CrashReportData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: send
import org.acra.collector.CrashReportData; //导入依赖的package包/类
@Override
public void send(CrashReportData report) throws ReportSenderException {
String log = createCrashLog(report);
String url = BASE_URL + ACRA.getConfig().formKey() + CRASHES_PATH;
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("raw", log));
parameters.add(new BasicNameValuePair("userID", report.get(ReportField.INSTALLATION_ID)));
parameters.add(new BasicNameValuePair("contact", report.get(ReportField.USER_EMAIL)));
parameters.add(new BasicNameValuePair("description", report.get(ReportField.USER_COMMENT)));
httpPost.setEntity(new UrlEncodedFormEntity(parameters, HTTP.UTF_8));
httpClient.execute(httpPost);
}
catch (Exception e) {
e.printStackTrace();
}
}
示例2: send
import org.acra.collector.CrashReportData; //导入依赖的package包/类
@Override
public void send(CrashReportData report) throws ReportSenderException {
String log = createCrashLog(report);
String url = BASE_URL + ACRA.getConfig().formKey() + CRASHES_PATH;
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("raw", log));
parameters.add(new BasicNameValuePair("userID", report.get(ReportField.INSTALLATION_ID)));
parameters.add(new BasicNameValuePair("contact", report.get(ReportField.USER_EMAIL)));
parameters.add(new BasicNameValuePair("description", report.get(ReportField.USER_COMMENT)));
httpPost.setEntity(new UrlEncodedFormEntity(parameters, HTTP.UTF_8));
httpClient.execute(httpPost);
}
catch (Exception e) {
e.printStackTrace();
}
}
示例3: send
import org.acra.collector.CrashReportData; //导入依赖的package包/类
@Override
public void send(CrashReportData report) throws ReportSenderException {
final Map<String, String> finalReport = remap(report);
try {
OutputStreamWriter osw = new OutputStreamWriter(crashReport);
Set<Entry<String, String>> set = finalReport.entrySet();
Iterator<Entry<String, String>> i = set.iterator();
while (i.hasNext()) {
Map.Entry<String, String> me = (Entry<String, String>) i.next();
osw.write("[" + me.getKey() + "]=" + me.getValue());
}
osw.flush();
osw.close();
} catch (IOException e) {
Log.e(TAG, "IO ERROR", e);
}
}
示例4: load
import org.acra.collector.CrashReportData; //导入依赖的package包/类
/**
* Loads properties from the specified {@code InputStream}. The encoding is
* ISO8859-1.
*
* @param fileName Name of the report file from which to load the CrashData.
* @return CrashReportData read from the supplied InputStream.
* @throws java.io.IOException if error occurs during reading from the {@code InputStream}.
*/
public CrashReportData load(String fileName) throws IOException {
final FileInputStream in = context.openFileInput(fileName);
if (in == null) {
throw new IllegalArgumentException("Invalid crash report fileName : " + fileName);
}
try {
final BufferedInputStream bis = new BufferedInputStream(in, ACRAConstants.DEFAULT_BUFFER_SIZE_IN_BYTES);
bis.mark(Integer.MAX_VALUE);
final boolean isEbcdic = isEbcdic(bis);
bis.reset();
if (!isEbcdic) {
return load(new InputStreamReader(bis, "ISO8859-1")); //$NON-NLS-1$
} else {
return load(new InputStreamReader(bis)); //$NON-NLS-1$
}
} finally {
in.close();
}
}
示例5: store
import org.acra.collector.CrashReportData; //导入依赖的package包/类
/**
* Stores the mappings in this Properties to the specified OutputStream,
* putting the specified comment at the beginning. The output from this
* method is suitable for being read by the load() method.
*
* @param crashData CrashReportData to save.
* @param fileName Name of the file to which to store the CrashReportData.
* @throws java.io.IOException if the CrashReportData could not be written to the OutputStream.
*/
public void store(CrashReportData crashData, String fileName) throws IOException {
final OutputStream out = context.openFileOutput(fileName, Context.MODE_PRIVATE);
try {
final StringBuilder buffer = new StringBuilder(200);
final OutputStreamWriter writer = new OutputStreamWriter(out, "ISO8859_1"); //$NON-NLS-1$
for (final Map.Entry<ReportField, String> entry : crashData.entrySet()) {
final String key = entry.getKey().toString();
dumpString(buffer, key, true);
buffer.append('=');
dumpString(buffer, entry.getValue(), false);
buffer.append(LINE_SEPARATOR);
writer.write(buffer.toString());
buffer.setLength(0);
}
writer.flush();
} finally {
out.close();
}
}
示例6: sendCrashReport
import org.acra.collector.CrashReportData; //导入依赖的package包/类
/**
* Sends the report with all configured ReportSenders. If at least one
* sender completed its job, the report is considered as sent and will not
* be sent again for failing senders.
*
* @param errorContent
* Crash data.
* @throws ReportSenderException
* if unable to send the crash report.
*/
private void sendCrashReport(CrashReportData errorContent) throws ReportSenderException {
if (!ACRA.isDebuggable() || ACRA.getConfig().sendReportsInDevMode()) {
boolean sentAtLeastOnce = false;
for (ReportSender sender : reportSenders) {
try {
sender.send(errorContent);
// If at least one sender worked, don't re-send the report
// later.
sentAtLeastOnce = true;
} catch (ReportSenderException e) {
if (!sentAtLeastOnce) {
throw e; // Don't log here because we aren't dealing
// with the Exception here.
} else {
Log.w(LOG_TAG,
"ReportSender of class "
+ sender.getClass().getName()
+ " failed but other senders completed their task. ACRA will not send this report again.");
}
}
}
}
}
示例7: send
import org.acra.collector.CrashReportData; //导入依赖的package包/类
@Override
public void send(CrashReportData report) throws ReportSenderException {
Uri formUri = mFormUri == null ? Uri.parse(String.format(ACRA.getConfig().googleFormUrlFormat(), ACRA
.getConfig().formKey())) : mFormUri;
final Map<String, String> formParams = remap(report);
// values observed in the GoogleDocs original html form
formParams.put("pageNumber", "0");
formParams.put("backupCache", "");
formParams.put("submit", "Envoyer");
try {
final URL reportUrl = new URL(formUri.toString());
Log.d(LOG_TAG, "Sending report " + report.get(ReportField.REPORT_ID));
Log.d(LOG_TAG, "Connect to " + reportUrl);
final HttpRequest request = new HttpRequest();
request.setConnectionTimeOut(ACRA.getConfig().connectionTimeout());
request.setSocketTimeOut(ACRA.getConfig().socketTimeout());
request.setMaxNrRetries(ACRA.getConfig().maxNumberOfRequestRetries());
request.send(reportUrl, Method.POST, HttpRequest.getParamsAsFormString(formParams), Type.FORM);
} catch (IOException e) {
throw new ReportSenderException("Error while sending report to Google Form.", e);
}
}
示例8: send
import org.acra.collector.CrashReportData; //导入依赖的package包/类
public void send(@NonNull Context context, @NonNull CrashReportData errorContent)
throws ReportSenderException {
Intent emailIntent = new Intent("android.intent.action.SENDTO");
emailIntent.setData(Uri.fromParts("mailto", this.config.mailTo(), (String) null));
emailIntent.addFlags(268435456);
String[] subjectBody = this.buildSubjectBody(context, errorContent);
emailIntent.putExtra("android.intent.extra.SUBJECT", subjectBody[0]);
emailIntent.putExtra("android.intent.extra.TEXT", subjectBody[1]);
context.startActivity(emailIntent);
}
示例9: buildSubjectBody
import org.acra.collector.CrashReportData; //导入依赖的package包/类
private String[] buildSubjectBody(Context context, CrashReportData errorContent) {
ImmutableSet fields = this.config.getReportFields();
if (fields.isEmpty()) {
fields = new ImmutableSet<ReportField>(ACRAConstants.DEFAULT_MAIL_REPORT_FIELDS);
}
String subject = context.getPackageName() + " Crash Report";
StringBuilder builder = new StringBuilder();
Iterator var4 = fields.iterator();
while (var4.hasNext()) {
ReportField field = (ReportField) var4.next();
builder.append(field.toString()).append('=');
builder.append(errorContent.get(field));
builder.append('\n');
if ("STACK_TRACE".equals(field.toString())) {
String stackTrace = errorContent.get(field);
if (stackTrace != null) {
subject = context.getPackageName() + ": "
+ stackTrace.substring(0, stackTrace.indexOf('\n'));
if (subject.length() > 72) {
subject = subject.substring(0, 72);
}
}
}
}
return new String[]{subject, builder.toString()};
}
示例10: createCrashLog
import org.acra.collector.CrashReportData; //导入依赖的package包/类
private String createCrashLog(CrashReportData report) {
Date now = new Date();
StringBuilder log = new StringBuilder();
log.append("Package: " + report.get(ReportField.PACKAGE_NAME) + "\n");
log.append("Version: " + report.get(ReportField.APP_VERSION_CODE) + "\n");
log.append("Android: " + report.get(ReportField.ANDROID_VERSION) + "\n");
log.append("Manufacturer: " + android.os.Build.MANUFACTURER + "\n");
log.append("Log: " + report.get(ReportField.LOGCAT) + "\n");
log.append("Date: " + now + "\n");
log.append("\n");
log.append(report.get(ReportField.STACK_TRACE));
return log.toString();
}
示例11: send
import org.acra.collector.CrashReportData; //导入依赖的package包/类
public void send(@NonNull Context context, @NonNull CrashReportData errorContent)
throws ReportSenderException {
Intent emailIntent = new Intent("android.intent.action.SENDTO");
emailIntent.setData(Uri.fromParts("mailto", this.config.mailTo(), null));
emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
String[] subjectBody = this.buildSubjectBody(context, errorContent);
emailIntent.putExtra("android.intent.extra.SUBJECT", subjectBody[0]);
emailIntent.putExtra("android.intent.extra.TEXT", subjectBody[1]);
context.startActivity(emailIntent);
}
示例12: buildSubjectBody
import org.acra.collector.CrashReportData; //导入依赖的package包/类
private String[] buildSubjectBody(Context context, CrashReportData errorContent) {
ImmutableSet fields = this.config.getReportFields();
if (fields.isEmpty()) {
fields = new ImmutableSet<>(ACRAConstants.DEFAULT_MAIL_REPORT_FIELDS);
}
String subject = context.getPackageName() + " Crash Report";
StringBuilder builder = new StringBuilder();
for (Object field1 : fields) {
ReportField field = (ReportField) field1;
builder.append(field.toString()).append('=');
builder.append(errorContent.get(field));
builder.append('\n');
if ("STACK_TRACE".equals(field.toString())) {
String stackTrace = errorContent.get(field).toString();
if (stackTrace != null) {
subject = context.getPackageName() + ": "
+ stackTrace.substring(0, stackTrace.indexOf('\n'));
if (subject.length() > 72) {
subject = subject.substring(0, 72);
}
}
}
}
return new String[]{subject, builder.toString()};
}
示例13: onCreate
import org.acra.collector.CrashReportData; //导入依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
if (!BuildConfig.DEBUG) {
ACRA.init(this);
ACRA.getErrorReporter().addReportSender(new ReportSender() {
@Override
public void send(Context context, CrashReportData errorContent) throws ReportSenderException {
context.getSharedPreferences("crash", MODE_MULTI_PROCESS).edit()
.putBoolean("crashed", true).commit();
}
});
ACRA.getErrorReporter().setEnabled(true);
}
}
示例14: send
import org.acra.collector.CrashReportData; //导入依赖的package包/类
public void send(@NonNull Context context, @NonNull CrashReportData errorContent)
throws ReportSenderException {
Intent emailIntent = new Intent("android.intent.action.SENDTO");
emailIntent.setData(Uri.fromParts("mailto", this.config.mailTo(), (String) null));
emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
String[] subjectBody = this.buildSubjectBody(context, errorContent);
emailIntent.putExtra("android.intent.extra.SUBJECT", subjectBody[0]);
emailIntent.putExtra("android.intent.extra.TEXT", subjectBody[1]);
context.startActivity(emailIntent);
}
示例15: sendCrash
import org.acra.collector.CrashReportData; //导入依赖的package包/类
private void sendCrash() {
// Retrieve user comment
final String comment = userComment != null ? userComment.getText().toString() : "";
// Store the user email
final String usrEmail;
if (prefs != null && userEmail != null) {
usrEmail = userEmail.getText().toString();
final Editor prefEditor = prefs.edit();
prefEditor.putString(ACRA.PREF_USER_EMAIL_ADDRESS, usrEmail);
prefEditor.commit();
} else {
usrEmail = "";
}
final CrashReportPersister persister = new CrashReportPersister(getApplicationContext());
try {
Log.d(LOG_TAG, "Add user comment to " + mReportFileName);
final CrashReportData crashData = persister.load(mReportFileName);
crashData.put(USER_COMMENT, comment);
crashData.put(USER_EMAIL, usrEmail);
persister.store(crashData, mReportFileName);
} catch (IOException e) {
Log.w(LOG_TAG, "User comment not added: ", e);
}
// Start the report sending task
Log.v(ACRA.LOG_TAG, "About to start SenderWorker from CrashReportDialog");
ACRA.getErrorReporter().startSendingReports(false, true);
// Optional Toast to thank the user
final int toastId = ACRA.getConfig().resDialogOkToast();
if (toastId != 0) {
ToastSender.sendToast(getApplicationContext(), toastId, Toast.LENGTH_LONG);
}
}