背景:
- 我的应用程序使用Webview显示一份包含一些数据的报告。
- 此Webview具有顶部工具栏,其中包含一个打印按钮。
- 单击打印按钮时,会弹出一个菜单,让用户从可以打印报告的应用程序列表中进行选择。
- 打印过程:对报告进行截屏,压缩以减小其大小,将PNG发送到打印机应用程序。 问题:
- 当打印机应用程序打开要打印的图像时,我收到一个ANR,说明我的后台应用程序停止工作了。
- 如果我在Android上按下返回按钮,则应用程序仍然处于活动状态,而且我可以无错误地导航,这很奇怪,因为我刚刚收到了停止工作的警报。
- 我的应用程序使用Webview显示一份包含一些数据的报告。
- 此Webview具有顶部工具栏,其中包含一个打印按钮。
- 单击打印按钮时,会弹出一个菜单,让用户从可以打印报告的应用程序列表中进行选择。
- 打印过程:对报告进行截屏,压缩以减小其大小,将PNG发送到打印机应用程序。 问题:
- 当打印机应用程序打开要打印的图像时,我收到一个ANR,说明我的后台应用程序停止工作了。
- 如果我在Android上按下返回按钮,则应用程序仍然处于活动状态,而且我可以无错误地导航,这很奇怪,因为我刚刚收到了停止工作的警报。
以下是一些代码供参考:
截屏并发送到打印机应用程序的代码:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.print) {
Bitmap bitmap = Util.screenShot(mWebView);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
File file = new File(Environment.getExternalStorageDirectory() + File.separator + "screenshot.png");
try {
file.createNewFile();
FileOutputStream fo = new FileOutputStream(file);
fo.write(bytes.toByteArray());
fo.close();
} catch (IOException e) {
e.printStackTrace();
}
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/png");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
日志:
03-23 14:32:54.726 11347-11388/br.gov.go.agrodefesa.tabletagrodefesa E/IMGSRV: kickresource.c:1130: Debug assertion failed!
03-23 14:32:54.836 9039-9039/? A/google-breakpad: M B0DE6000 00018000 00015000 000000000000000000000000000000000 data@app@br.gov.go.agrodefesa.tabletagrodefesa-1@base.apk@classes.dex
03-23 14:32:54.876 11347-11388/br.gov.go.agrodefesa.tabletagrodefesa W/google-breakpad: ### ### ### ### ### ### ### ### ### ### ### ### ###
03-23 14:32:54.876 11347-11388/br.gov.go.agrodefesa.tabletagrodefesa W/google-breakpad: Chrome build fingerprint:
03-23 14:32:54.876 11347-11388/br.gov.go.agrodefesa.tabletagrodefesa W/google-breakpad: 1.27
03-23 14:32:54.876 11347-11388/br.gov.go.agrodefesa.tabletagrodefesa W/google-breakpad: 1
03-23 14:32:54.876 11347-11388/br.gov.go.agrodefesa.tabletagrodefesa W/google-breakpad: ### ### ### ### ### ### ### ### ### ### ### ### ###
03-23 14:32:54.876 11347-11388/br.gov.go.agrodefesa.tabletagrodefesa A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 11388 (RenderThread)
03-23 14:32:54.976 9769-9769/? I/DEBUG: pid: 11347, tid: 11388, name: RenderThread >>> br.gov.go.agrodefesa.tabletagrodefesa <<<
03-23 14:32:55.056 1710-1777/? D/UsageStatistics: Pkg: br.gov.go.agrodefesa.tabletagrodefesa ForegroundTime: 2701177 FirstTime: 3-22-2017 21:00:00:000 LastTime: 3-23-2017 14:32:54:057 LastTimeUsed: 3-23-2017 14:32:54:057
03-23 14:32:55.466 524-1117/? I/WindowState: WIN DEATH: Window{2ba92055 u0 br.gov.go.agrodefesa.tabletagrodefesa/br.gov.go.agrodefesa.tabletagrodefesa.activities.TermoFiscalizacaoListActivity}
03-23 14:32:55.476 524-980/? I/WindowState: WIN DEATH: Window{1892d68d u0 br.gov.go.agrodefesa.tabletagrodefesa/br.gov.go.agrodefesa.tabletagrodefesa.activities.ImpressaoActivity}
03-23 14:32:55.496 524-654/? I/ActivityManager: Process br.gov.go.agrodefesa.tabletagrodefesa (pid 11347) has died
currentTimeMillis
计算返回 80。此外,我尝试将代码移动到AsyncTask
中,但 ANR 仍然出现。 - MurifoX