Android 当应用程序在运行时停止时,如何查找错误?
我有一个Android应用程序,它具有将SQLiteDatabase导出到外部存储中的文件的功能。它在我的手机(Redmi 4X)上运行正常,但在其他手机(如三星SM-J105b)上,它在我备份时崩溃 以下是我的备份代码:Android 当应用程序在运行时停止时,如何查找错误?,android,sqlite,backup,logcat,Android,Sqlite,Backup,Logcat,我有一个Android应用程序,它具有将SQLiteDatabase导出到外部存储中的文件的功能。它在我的手机(Redmi 4X)上运行正常,但在其他手机(如三星SM-J105b)上,它在我备份时崩溃 以下是我的备份代码: private void backupDB() throws IOException { String backupDirectory = Environment.getExternalStorageDirectory() + "/FDRMobile/Backups
private void backupDB() throws IOException {
String backupDirectory = Environment.getExternalStorageDirectory() + "/FDRMobile/Backups/";
File backupDir = new File( backupDirectory, "");
if (!backupDir.exists()) {
backupDir.mkdirs();
}
final String inFileName = "/data/data/com.scbpfsdgis.fdrmobile/databases/FEMobile.db";
File dbFile = new File(inFileName);
FileInputStream fis = new FileInputStream(dbFile);
Date date = new Date();
DateFormat df = new SimpleDateFormat("YYYY-MM-dd_HHMMSS", Locale.getDefault());
String bakFile = "BAK_" + df.format(date) + ".db";
this.backupFileName = bakFile;
backupDirectory += bakFile;
// Open the empty db as the output stream
OutputStream output = new FileOutputStream(backupDirectory);
// Transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = fis.read(buffer))>0){
output.write(buffer, 0, length);
}
// Close the streams
output.flush();
output.close();
fis.close();
}
我不知道如何编写logcat文本文件。Android应用程序将运行应用程序的日志存储在一个文件中。可以使用以下步骤检索日志:
为什么要将logcat写入文件?您的意思是,如果任何设备发生故障,您希望接收发送到电子邮件的日志吗?故障报告服务将是一种更简单的方法,Firebase crashlytics是一个很好的选择start@TamHuynh-我想知道为什么应用程序会崩溃,所以可能会出现错误日志。如果我能得到堆栈跟踪,我会在一个文本文件中,它会更好。你知道应用程序可能在这个代码中的什么地方崩溃了吗?@FarabiAbdelwahed建议你使用
Firebase Crashlytics
,我目前也使用它以前的Fabric.io Crashlytics
工具。它几乎会将堆栈跟踪、设备信息、你的自定义信息与崩溃一起推送你也应该试试看你的仪表盘和电子邮件