Prevent crash

pull/153/head
M66B 6 years ago
parent 2bfee5ff6e
commit 5bb959448c

@ -2431,13 +2431,18 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
@Override
public void onPageFinished(WebView view, String url) {
PrintManager printManager = (PrintManager) context.getSystemService(Context.PRINT_SERVICE);
String jobName = context.getString(R.string.app_name);
if (!TextUtils.isEmpty(data.message.subject))
jobName += " - " + data.message.subject;
PrintDocumentAdapter adapter = printWebView.createPrintDocumentAdapter(jobName);
printManager.print(jobName, adapter, new PrintAttributes.Builder().build());
printWebView = null;
try {
PrintManager printManager = (PrintManager) context.getSystemService(Context.PRINT_SERVICE);
String jobName = context.getString(R.string.app_name);
if (!TextUtils.isEmpty(data.message.subject))
jobName += " - " + data.message.subject;
PrintDocumentAdapter adapter = printWebView.createPrintDocumentAdapter(jobName);
printManager.print(jobName, adapter, new PrintAttributes.Builder().build());
} catch (Throwable ex) {
Log.e(ex);
} finally {
printWebView = null;
}
}
});
@ -2557,6 +2562,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
popupMenu.getMenu().findItem(R.id.menu_share).setEnabled(data.message.content);
popupMenu.getMenu().findItem(R.id.menu_print).setEnabled(hasWebView && data.message.content);
popupMenu.getMenu().findItem(R.id.menu_print).setVisible(Helper.canPrint(context));
popupMenu.getMenu().findItem(R.id.menu_show_headers).setChecked(show_headers);
popupMenu.getMenu().findItem(R.id.menu_show_headers).setEnabled(data.message.uid != null);

@ -1035,6 +1035,11 @@ public class Helper {
return false;
}
static boolean canPrint(Context context) {
PackageManager pm = context.getPackageManager();
return pm.hasSystemFeature("android.software.print");
}
public static String getFingerprint(Context context) {
try {
PackageManager pm = context.getPackageManager();

Loading…
Cancel
Save