- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想使用最新的 Acra 4.9.0 将崩溃报告写入文本文件。我不能举例说明这个最新版本。我尝试使用可用的文档。
Acra 已启用但它没有写入文件。
myApp
package com.myApp;
import org.acra.ACRA;
import android.app.AlertDialog;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.KeyEvent;
import android.view.View;
import com.myApp.Application.AppLauncher;
import com.myApp.interfaces.AppEvents;
import com.myApp.R;
import com.utils.Config;
import com.utils.Constants;
import com.utils.DeviceValidator;
public class myApp extends FragmentActivity
{
private AppLauncher appLauncher = null;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
if(!ACRA.isACRASenderServiceProcess())
{
setContentView(R.layout.activity_myApp);
appLauncher = new AppLauncher();
appLauncher.registerEventListener(appEventsListener);
appLauncher.initApp(this);
}
}
@Override
public void onPause() {
super.onPause();
if(!DeviceValidator.isDeviceValid())
{
return;
}
appLauncher.activityOnPause();
}
@Override
protected void onRestart() {
super.onRestart();
}
@Override
protected void onStart()
{
super.onStart();
}
@Override
public void onResume()
{
super.onResume();
appLauncher.activityOnResume();
}
}
AcraApplication
package com.myAPP;
import org.acra.ACRA;
import org.acra.ReportField;
import org.acra.ReportingInteractionMode;
import org.acra.annotation.ReportsCrashes;
import org.acra.sender.HttpSender.Method;
import android.app.Application;
@ReportsCrashes(
formUri = "http://staging.jemtv.com/variable_dump/index.php",
customReportContent = { ReportField.REPORT_ID, ReportField.DEVICE_ID, ReportField.APP_VERSION_NAME, ReportField.ANDROID_VERSION, ReportField.STACK_TRACE, ReportField.CUSTOM_DATA, ReportField.LOGCAT },
httpMethod = Method.POST,
reportSenderFactoryClasses = org.acra.util.MyOwnSenderFactory.class,
mode = ReportingInteractionMode.SILENT
)
public class AcraApplication extends Application
{
public AcraApplication()
{
super();
}
@Override
public void onCreate() {
super.onCreate();
ACRA.init(this);
}
}
MyOwnSender
package org.acra.util;
import java.io.File;
import java.io.FileOutputStream;
import org.acra.ReportField;
import org.acra.collector.CrashReportData;
import org.acra.config.ACRAConfiguration;
import org.acra.sender.ReportSender;
import org.acra.sender.ReportSenderException;
import android.content.Context;
import android.support.annotation.NonNull;
import android.util.Log;
public class MyOwnSender implements ReportSender {
private static final String FILE_NAME = "AcraReport.txt";
//private final Map<ReportField, String> mMapping = new HashMap<ReportField, String>();
//private FileWriter crashReport = null;
MyOwnSender(Context context, @NonNull ACRAConfiguration config)
{
Log.d("testAcra", "MyOwnSender created");
/* File logFile = new File(context.getFilesDir().getPath() + "/" + FILE_NAME, FILE_NAME);
try {
crashReport = new FileWriter(logFile, true);
} catch (IOException e) {
e.printStackTrace();
}*/
}
@Override
public void send(Context context, CrashReportData report) throws ReportSenderException
{
// Iterate over the CrashReportData instance and do whatever
// you need with each pair of ReportField key / String value
String finalReport = createCrashReport(report);
String tempFile = context.getFilesDir().getPath() + "/" + FILE_NAME;
try
{
File detailedFile = new File(tempFile);
if(!detailedFile.exists())
detailedFile.createNewFile();
FileOutputStream stream = new FileOutputStream(detailedFile, true);
stream.write(finalReport.getBytes());
Log.d("testAcra","adding to file: "+stream);
stream.close();
}
catch (Exception e)
{
e.printStackTrace();
}
/*final Map<String, String> finalReport = remap(report);
try {
BufferedWriter buf = new BufferedWriter(crashReport);
Set<Entry<String, String>> set = reportBody.entrySet();
Iterator<Entry<String, String>> i = set.iterator();
while (i.hasNext()) {
Map.Entry<String, String> me = (Entry<String, String>) i.next();
buf.append("[" + me.getKey() + "]=" + me.getValue());
}
buf.flush();
buf.close();
} catch (IOException e) {
Log.e("TAG", "IO ERROR", e);
}*/
}
private String createCrashReport(CrashReportData crashReportData){
StringBuilder body = new StringBuilder();
body.append("ReportID : " + crashReportData.getProperty(ReportField.REPORT_ID))
.append("\n")
.append("DeviceID : " + crashReportData.getProperty(ReportField.DEVICE_ID))
.append("\n")
.append("AppVersionName : " + crashReportData.getProperty(ReportField.APP_VERSION_NAME))
.append("\n")
.append("Android Version : " + crashReportData.getProperty(ReportField.ANDROID_VERSION))
.append("\n")
.append("CustomData : " + crashReportData.getProperty(ReportField.CUSTOM_DATA))
.append("\n")
.append("STACK TRACE : \n" + crashReportData.getProperty(ReportField.STACK_TRACE))
.append("\n")
.append("LogCAT : \n" + crashReportData.getProperty(ReportField.LOGCAT));
return body.toString();
}
/* private Map<String, String> remap(Map<ReportField, String> report) {
Set<ReportField>fields = ACRA.getConfig().getReportFields();
final Map<String, String> finalReport = new HashMap<String, String>(report.size());
for (ReportField field : fields)
{
if (mMapping == null || mMapping.get(field) == null)
finalReport.put(field.toString(), report.get(field));
else
finalReport.put(mMapping.get(field), report.get(field));
}
return finalReport;
}*/
}
MyOwnSenderFactory
package org.acra.util;
import org.acra.config.ACRAConfiguration;
import org.acra.sender.ReportSender;
import org.acra.sender.ReportSenderFactory;
import android.content.Context;
import android.support.annotation.NonNull;
public class MyOwnSenderFactory implements ReportSenderFactory {
// NB requires a no arg constructor.
/*MyOwnSenderFactory()
{
Log.e("testAcra", "MyOwnSenderFactory created");
}*/
@Override
@NonNull
public ReportSender create(@NonNull Context context, @NonNull ACRAConfiguration config) {
// TODO Auto-generated method stub
return new MyOwnSender(context, config);
}
}
最佳答案
因为我使用的是 jar 文件而不是 aar在我的 list 中我不见了
<service
android:name="org.acra.sender.SenderService"
android:exported="false"
android:process=":acra" />
enter code here
这就是为什么在 Acra 中使用的 SendeService 没有启动的原因。
关于android - ACRA 4.9.0 : How can I write ACRA report to file (in Application data folder),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39348372/
当我在 ./blah/中创建 index.js 时使用 webpack,然后执行 import blah from './blah' 它成功地从 index.js 获取 但是,我的代码编辑器现在充满了
我正在尝试使用 Webpack 4 将图像文件夹从 src 文件夹导入(移动)到 dist 文件夹,但与 Gulp 不同,这个任务在 Webpack 中看起来非常复杂,即使我什至没有尝试搞乱目前,我只
这个问题已经有答案了: Update : Move files from one folder to another based on file extension (3 个回答) 已关闭 4 年前。
我有一个文件夹路径存储在属性 nightly.basepath 中(这里的值是 /path/to/my/nightly ): /path/to/my/nightly |- build_201003
这是我的代码。非常简单,除了当它创建实际文件夹时文件夹名称而不是文件夹名称,即“Test-Folder”它创建“@{Folder=Test-folder}/” $Folders = Import-Cs
我想复制一个包含多个文件夹的文件夹,并且该文件夹包含多个文件。如果此文件夹存在,我想将它们保留在里面,并覆盖这些文件(如果存在)。如果文件不存在,则会自然添加它们。 _ = try FileManag
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我想弄清楚 IMAP 的 search (带参数: "unseen all" )命令是通过搜索邮箱中的所有文件夹还是仅搜索当前选定的文件夹来工作? IE。选择时INBOX并发出 search命令,它没
我正在尝试将我的网站重定向到 www.domain.tld/folder/ 来自 www.domain.tld/folder/index.php?params=blah¶m2=etc 我已经尝
我正在尝试让我的网站重定向到 www.domain.tld/folder/ 来自 www.domain.tld/folder/index.php?params=blah¶m2=etc 我试过:
在 Eclipse IDE 中创建新的 Java(不是 JavaEE)项目时,我看到一个选项,上面写着Allow output folders for source folders。 那是干什么用的?
我已经关注 Jenkins extending pipeline with shared libraries 有人提到 The src directory should look like stand
我在 Visual Basic 2010 中遇到一个问题:如何将所有子文件夹(仅子文件夹,而不是主文件夹)复制到另一个文件夹中? 谢谢您的帮助! 最佳答案 您需要递归遍历所有文件和文件夹并复制它们。这
我正在尝试使用 groovy 脚本从 jenkins 收集数据并收到错误: unable to resolve class com.cloudbees.hudson.plugins.folder.Fo
我使用Intellij IDEA开发一个web项目,项目中有一些源码文件夹。 我想将不同源文件夹中的代码编译到不同的编译文件夹。 我知道在myeclipse中有一个功能“allow output fo
我有 com.company.database.mysql 和 com.company.database.sqlite。我只想包含 com.company.database.mysql。 我的代码组织
我正在 Tomcat 服务器上使用 eclipse 开发一个小 servlet。 我想从这个 servlet 中包含一些 jsp 文件,它非常适合该文件 WEB-INF/website/NewFile
假设我有一个目录,里面有一堆网站名称。 即 dev.domain.com dev.domain2.com dev.domain3.com 如何将它们重命名为 .com在使用管道和/或重定向 bash
我刚刚在 redis install_server 中遇到了一个错误 script它有一个硬编码: DEFAULT_CONFIG="../redis.conf" 所以当这个脚本不是从它自己的文件夹运行
我有一个非常简单的 WAR 项目,我想在所有已编译 Java 类所在的类输出文件夹的顶部包含一个名为 META-INF 的目录。我正在使用 Maven,但似乎默认情况下 Maven 不会包含任何不是
我是一名优秀的程序员,十分优秀!