EddyVerbruggen / nativescript-printer

:fax: Send an image or the screen contents to a physical printer
MIT License
36 stars 13 forks source link

v2.0.0 crashes Android when using with a NativeScript 6.5.3 project #29

Open methompson opened 3 years ago

methompson commented 3 years ago

I added nativescript-printer to an existing 6.5.3 project and instantiation of a Printer object causes the Android application to crash.

Line 17 of printer.android.ts causes the application to crash: this.printManager = Utils.ad.getApplicationContext().getSystemService(android.content.Context.PRINT_SERVICE);

The problem is in the import of Utils. Older versions of @nativescript/core don't have 'ad' in the definition of Utils. I'm hesitant to upgrade @nativescript/core because previous attempts at upgrading the application to NS 7 did not go well.

Changing the import to import * as utils from '@nativescript/core/utils/utils'; and changing line 17 to this.printManager = utils.ad.getApplicationContext().getSystemService(android.content.Context.PRINT_SERVICE); fixes this issue.

I've made a PR to fix the issue.