From ce5ace90b365db777f5344e993df4e71c5619f92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Fri, 23 Dec 2016 18:08:38 +0100 Subject: [PATCH] Fix broken interfaces with newest Android versions --- src/android/ext/PrintManager.java | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/android/ext/PrintManager.java b/src/android/ext/PrintManager.java index d1afe89..1ef8322 100644 --- a/src/android/ext/PrintManager.java +++ b/src/android/ext/PrintManager.java @@ -22,6 +22,7 @@ package de.appplant.cordova.plugin.printer.ext; import android.content.Context; +import android.os.Build; import android.print.PrintJob; import android.print.PrintJobId; @@ -107,8 +108,18 @@ public final class PrintManager { * @return The found service list or an empty list. */ public final List getInstalledPrintServices () { - List printers = (List) Meta.invokeMethod(getInstance(), - "getInstalledPrintServices"); + List printers; + + if (Build.VERSION.SDK_INT < 24) { + printers = (List) Meta.invokeMethod(getInstance(), + "getInstalledPrintServices"); + } else { + Method getPrintServicesMethod = Meta.getMethod( + getInstance().getClass(), "getPrintServices", int.class); + + printers = (List) Meta.invokeMethod(getInstance(), + getPrintServicesMethod, 3); + } ArrayList services = new ArrayList(); @@ -129,8 +140,18 @@ public final class PrintManager { * @return The found service list or an empty list. */ public final List getEnabledPrintServices () { - List printers = (List) Meta.invokeMethod(getInstance(), - "getEnabledPrintServices"); + List printers; + + if (Build.VERSION.SDK_INT < 24) { + printers = (List) Meta.invokeMethod(getInstance(), + "getEnabledPrintServices"); + } else { + Method getPrintServicesMethod = Meta.getMethod( + getInstance().getClass(), "getPrintServices", int.class); + + printers = (List) Meta.invokeMethod(getInstance(), + getPrintServicesMethod, 1); + } ArrayList services = new ArrayList();