Launch the Android Studio environment and create a new project, entering CustomPrint into the Application name field and ebookfrenzy.com as the Company Domain setting before clicking on the Next button.
On the form factors screen, enable the Phone and Tablet option and set the minimum SDK setting to API 1921: Android 45.4 0 (KitKatLollipop). Continue to proceed through the screens, requesting the creation of a blank activity named CustomPrintActivity with a corresponding layout and menu resource files named activity_custom_printand menu_custom_print respectively.
Load the activity_custom_print.xml layout file into the Designer tool and, in Design mode, select and delete the “Hello World!” TextView object. Drag and drop a Button view from the Form Widgets section of the palette and position it in the center of the layout view. Double click on the Button view, and change the text displayed to “Print Document”. Extract the string to a new string resource named print_string. On completion, the user interface layout should match that shown in Figure 53-1:
[[Image:android_custom_document_print_uiandroid_custom_document_print_ui2.png|The Android Studio Designer layout for a custom printing example app]]
Figure 53-1
[[Image:android_print_page_rangeandroid_print_page_range2.png|The Android Printing Framework print dialog]]
Figure 53-2
Compile and run the application on a physical Android device that is running Android 4.4 or later. When the application has loaded, touch the “Print Document” button to initiate the print job and select a suitable target for the output (the Save to PDF option is a useful option for avoiding wasting paper and printer ink).
Exception encountered, of type "Error"
[149a2255] /index.php/Special:MobileDiff/18124 Error from line 434 of /var/www/techotopia/includes/diff/DairikiDiff.php: Call to undefined function each()
Backtrace:
#0 /var/www/techotopia/includes/diff/DairikiDiff.php(544): DiffEngine->diag()
#1 /var/www/techotopia/includes/diff/DairikiDiff.php(344): DiffEngine->compareSeq()
#2 /var/www/techotopia/includes/diff/DairikiDiff.php(227): DiffEngine->diffLocal()
#3 /var/www/techotopia/includes/diff/DairikiDiff.php(721): DiffEngine->diff()
#4 /var/www/techotopia/includes/diff/DairikiDiff.php(859): Diff->__construct()
#5 /var/www/techotopia/includes/diff/DairikiDiff.php(980): MappedDiff->__construct()
#6 /var/www/techotopia/extensions/MobileFrontend/includes/diff/InlineDiffFormatter.php(99): WordLevelDiff->__construct()
#7 /var/www/techotopia/includes/diff/DiffFormatter.php(140): InlineDiffFormatter->changed()
#8 /var/www/techotopia/includes/diff/DiffFormatter.php(82): DiffFormatter->block()
#9 /var/www/techotopia/extensions/MobileFrontend/includes/diff/InlineDifferenceEngine.php(117): DiffFormatter->format()
#10 /var/www/techotopia/includes/diff/DifferenceEngine.php(797): InlineDifferenceEngine->generateTextDiffBody()
#11 /var/www/techotopia/includes/diff/DifferenceEngine.php(728): DifferenceEngine->generateContentDiffBody()
#12 /var/www/techotopia/extensions/MobileFrontend/includes/specials/SpecialMobileDiff.php(241): DifferenceEngine->getDiffBody()
#13 /var/www/techotopia/extensions/MobileFrontend/includes/specials/SpecialMobileDiff.php(135): SpecialMobileDiff->showDiff()
#14 /var/www/techotopia/extensions/MobileFrontend/includes/specials/MobileSpecialPage.php(53): SpecialMobileDiff->executeWhenAvailable()
#15 /var/www/techotopia/includes/specialpage/SpecialPage.php(384): MobileSpecialPage->execute()
#16 /var/www/techotopia/includes/specialpage/SpecialPageFactory.php(553): SpecialPage->run()
#17 /var/www/techotopia/includes/MediaWiki.php(281): SpecialPageFactory::executePath()
#18 /var/www/techotopia/includes/MediaWiki.php(714): MediaWiki->performRequest()
#19 /var/www/techotopia/includes/MediaWiki.php(508): MediaWiki->main()
#20 /var/www/techotopia/index.php(41): MediaWiki->run()
#21 {main}