我一直在尝试将android打印对话框选项预设为用户定义的设置。但无论我为printAttributes提供什么选项,我都只在对话框中将ISO_A4页面大小作为默认值。
以下是我一直在使用的代码:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
int pageTypeValue = Integer.parseInt(mSettingsPreferences.getString(Utility.SETTINGS_PDF_SIZE_TYPE, "4"));
PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE);
String jobName = getString(R.string.app_name) + " Document";
PrintAttributes.Builder builder = new PrintAttributes.Builder();
builder.setMediaSize(getSelectedMediaSize(pageTypeValue));
printManager.print(jobName, new MyPrintAdapter("name_of_file", mFile, FinalPrescriptionActivity.this), builder.build());
其中getSelectedMediaSize(int value)返回MediaSize:
public PrintAttributes.MediaSize getSelectedMediaSize(int pageType) {
switch (pageType) {
case (0):
return PrintAttributes.MediaSize.ISO_A0;
case 1:
return PrintAttributes.MediaSize.ISO_A1;
case 2:
return PrintAttributes.MediaSize.ISO_A2;
case 3:
return PrintAttributes.MediaSize.ISO_A3;
case 4:
return PrintAttributes.MediaSize.ISO_A4;
case 5:
return PrintAttributes.MediaSize.ISO_A5;
case 6:
return PrintAttributes.MediaSize.ISO_A6;
case 7:
return PrintAttributes.MediaSize.ISO_A7;
case 8:
return PrintAttributes.MediaSize.ISO_A8;
case 9:
return PrintAttributes.MediaSize.NA_LETTER;
case 10:
return PrintAttributes.MediaSize.NA_INDEX_3X5;
}
return null;
}
有人可以帮我设置android打印对话框选项吗?