Committed by
David PHAM-VAN
- only set printManager once
- added null checking for activity - logged exception thrown in register with
Showing
1 changed file
with
12 additions
and
3 deletions
| @@ -73,9 +73,18 @@ public class PrintingPlugin extends PrintDocumentAdapter implements MethodCallHa | @@ -73,9 +73,18 @@ public class PrintingPlugin extends PrintDocumentAdapter implements MethodCallHa | ||
| 73 | * Plugin registration. | 73 | * Plugin registration. |
| 74 | */ | 74 | */ |
| 75 | public static void registerWith(Registrar registrar) { | 75 | public static void registerWith(Registrar registrar) { |
| 76 | - final MethodChannel channel = new MethodChannel(registrar.messenger(), "net.nfet.printing"); | ||
| 77 | - channel.setMethodCallHandler(new PrintingPlugin(registrar.activity(), channel)); | ||
| 78 | - printManager = (PrintManager) registrar.activity().getSystemService(Context.PRINT_SERVICE); | 76 | + try { |
| 77 | + final Activity activity = registrar.activity(); | ||
| 78 | + final MethodChannel channel = new MethodChannel(registrar.messenger(), "printing"); | ||
| 79 | + final PrintingPlugin plugin = new PrintingPlugin(activity, channel); | ||
| 80 | + channel.setMethodCallHandler(plugin); | ||
| 81 | + | ||
| 82 | + if (printManager == null && activity != null) { | ||
| 83 | + printManager = (PrintManager) activity.getSystemService(Context.PRINT_SERVICE); | ||
| 84 | + } | ||
| 85 | + } catch (Exception e) { | ||
| 86 | + Log.e("PrintingPlugin", "Registration failed", e); | ||
| 87 | + } | ||
| 79 | } | 88 | } |
| 80 | 89 | ||
| 81 | @Override | 90 | @Override |
-
Please register or login to post a comment