1 package foo.bar.printservice; 2 3 import android.app.Activity; 4 import android.content.Intent; 5 import android.os.Bundle; 6 import android.os.Handler; 7 import android.print.PageRange; 8 import android.print.PrintAttributes; 9 import android.print.PrintAttributes.MediaSize; 10 import android.print.PrintJobInfo; 11 import android.print.PrinterCapabilitiesInfo; 12 import android.print.PrinterInfo; 13 import android.printservice.PrintService; 14 15 public class CustomPrintOptionsActivity extends Activity { 16 17 @Override onCreate(Bundle savedInstanceState)18 protected void onCreate(Bundle savedInstanceState) { 19 super.onCreate(savedInstanceState); 20 } 21 22 @Override onResume()23 public void onResume() { 24 super.onResume(); 25 26 PrintJobInfo printJobInfo = (PrintJobInfo) getIntent().getParcelableExtra( 27 PrintService.EXTRA_PRINT_JOB_INFO); 28 PrinterInfo printerInfo = (PrinterInfo) getIntent().getParcelableExtra( 29 "android.intent.extra.print.EXTRA_PRINTER_INFO"); 30 31 PrinterCapabilitiesInfo capabilities = printerInfo.getCapabilities(); 32 33 PrintAttributes attributes = new PrintAttributes.Builder() 34 .setColorMode(PrintAttributes.COLOR_MODE_MONOCHROME) 35 .setMediaSize(MediaSize.ISO_A5) 36 .setResolution(capabilities.getResolutions().get(0)) 37 .build(); 38 39 PrintJobInfo.Builder builder = new PrintJobInfo.Builder(printJobInfo); 40 builder.setAttributes(attributes); 41 builder.setCopies(2); 42 builder.setAttributes(attributes); 43 builder.setPages(new PageRange[] {new PageRange(1, 1), new PageRange(3, 3)}); 44 builder.putAdvancedOption("EXTRA_FIRST_ADVANCED_OPTION", "OPALA"); 45 builder.putAdvancedOption("EXTRA_SECOND_ADVANCED_OPTION", 1); 46 47 PrintJobInfo newPrintJobInfo = builder.build(); 48 49 Intent result = new Intent(); 50 result.putExtra(PrintService.EXTRA_PRINT_JOB_INFO, newPrintJobInfo); 51 setResult(Activity.RESULT_OK, result); 52 53 finish(); 54 } 55 } 56