Fix bug report generation temp file
Use application space to store the temporary file if it cannot be stored in the default place.
This commit is contained in:
parent
b3f7a20857
commit
53b2381ad8
1 changed files with 21 additions and 14 deletions
|
@ -73,26 +73,32 @@ public class AboutActivity extends Activity implements OnClickListener {
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private File writeLogs(String logs, File directory) {
|
||||||
|
File tempFile = null;
|
||||||
|
try {
|
||||||
|
tempFile = File.createTempFile("bugreport", ".txt", directory);
|
||||||
|
tempFile.deleteOnExit();
|
||||||
|
FileWriter writer = new FileWriter(tempFile);
|
||||||
|
writer.append(logs);
|
||||||
|
return tempFile;
|
||||||
|
} catch (IOException e) {
|
||||||
|
Toast.makeText(this, getString(R.string.about_error_generating_bugreport_attachement), Toast.LENGTH_LONG).show();
|
||||||
|
Log.e(e, "couldn't write to temporary file");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void onLogsRead(String logs) {
|
private void onLogsRead(String logs) {
|
||||||
File tempFile;
|
|
||||||
if (logs == null) {
|
if (logs == null) {
|
||||||
Toast.makeText(this, getString(R.string.about_logs_not_found), Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, getString(R.string.about_logs_not_found), Toast.LENGTH_SHORT).show();
|
||||||
} else {
|
} else {
|
||||||
|
File tempFile = writeLogs(logs, null);
|
||||||
try {
|
if (tempFile == null) {
|
||||||
tempFile = File.createTempFile("bugreport", ".txt");
|
// If writing to temporary file to default location failed
|
||||||
tempFile.deleteOnExit();
|
// Write one to our storage place
|
||||||
FileWriter writer = new FileWriter(tempFile);
|
tempFile = writeLogs(logs, getFilesDir());
|
||||||
writer.append(logs);
|
|
||||||
} catch (IOException e) {
|
|
||||||
Toast.makeText(this, getString(R.string.about_error_generating_bugreport_attachement), Toast.LENGTH_LONG).show();
|
|
||||||
Log.e(e, "couldn't write to temporary file");
|
|
||||||
return;
|
|
||||||
} finally {
|
|
||||||
thread = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
intent.setType("plain/text");
|
intent.setType("plain/text");
|
||||||
|
@ -114,6 +120,7 @@ public class AboutActivity extends Activity implements OnClickListener {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
onLogsRead(logs);
|
onLogsRead(logs);
|
||||||
|
thread=null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
super.run();
|
super.run();
|
||||||
|
|
Loading…
Reference in a new issue