|
30 | 30 | import com.pspdfkit.PSPDFKit; |
31 | 31 | import com.pspdfkit.document.PdfDocument; |
32 | 32 | import com.pspdfkit.document.formatters.DocumentJsonFormatter; |
| 33 | +import com.pspdfkit.exceptions.InvalidPSPDFKitLicenseException; |
| 34 | +import com.pspdfkit.exceptions.PSPDFKitException; |
33 | 35 | import com.pspdfkit.flutter.pspdfkit.util.DocumentJsonDataProvider; |
34 | 36 | import com.pspdfkit.forms.ChoiceFormElement; |
35 | 37 | import com.pspdfkit.forms.EditableButtonFormElement; |
|
62 | 64 | */ |
63 | 65 | public class PspdfkitPlugin implements MethodCallHandler, PluginRegistry.RequestPermissionsResultListener, |
64 | 66 | FlutterPlugin, ActivityAware { |
65 | | - @NonNull private static final EventDispatcher eventDispatcher = EventDispatcher.getInstance(); |
| 67 | + @NonNull |
| 68 | + private static final EventDispatcher eventDispatcher = EventDispatcher.getInstance(); |
66 | 69 | private static final String LOG_TAG = "PSPDFKitPlugin"; |
67 | 70 |
|
68 | | - /** Hybrid technology where the application is supposed to be working on. */ |
| 71 | + /** |
| 72 | + * Hybrid technology where the application is supposed to be working on. |
| 73 | + */ |
69 | 74 | private static final String HYBRID_TECHNOLOGY = "Flutter"; |
70 | 75 |
|
71 | | - /** Atomic reference that prevents sending twice the permission result and throwing exception. */ |
72 | | - @NonNull private final AtomicReference<Result> permissionRequestResult; |
| 76 | + /** |
| 77 | + * Atomic reference that prevents sending twice the permission result and throwing exception. |
| 78 | + */ |
| 79 | + @NonNull |
| 80 | + private final AtomicReference<Result> permissionRequestResult; |
73 | 81 |
|
74 | | - @Nullable private ActivityPluginBinding activityPluginBinding; |
| 82 | + @Nullable |
| 83 | + private ActivityPluginBinding activityPluginBinding; |
75 | 84 |
|
76 | 85 | public PspdfkitPlugin() { |
77 | 86 | this.permissionRequestResult = new AtomicReference<>(); |
@@ -129,12 +138,20 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { |
129 | 138 | case "setLicenseKey": |
130 | 139 | String licenseKey = call.argument("licenseKey"); |
131 | 140 | requireNotNullNotEmpty(licenseKey, "License key"); |
132 | | - PSPDFKit.initialize(activity, licenseKey, new ArrayList<>(), HYBRID_TECHNOLOGY); |
| 141 | + try { |
| 142 | + PSPDFKit.initialize(activity, licenseKey, new ArrayList<>(), HYBRID_TECHNOLOGY); |
| 143 | + } catch (PSPDFKitException e) { |
| 144 | + result.error("PSPDFKitException", e.getMessage(), null); |
| 145 | + } |
133 | 146 | break; |
134 | 147 | case "setLicenseKeys": |
135 | 148 | String androidLicenseKey = call.argument("androidLicenseKey"); |
136 | 149 | requireNotNullNotEmpty(androidLicenseKey, "Android License key"); |
137 | | - PSPDFKit.initialize(activity, androidLicenseKey, new ArrayList<>(), HYBRID_TECHNOLOGY); |
| 150 | + try { |
| 151 | + PSPDFKit.initialize(activity, androidLicenseKey, new ArrayList<>(), HYBRID_TECHNOLOGY); |
| 152 | + } catch (PSPDFKitException e) { |
| 153 | + result.error("PSPDFKitException", e.getMessage(), null); |
| 154 | + } |
138 | 155 | break; |
139 | 156 | case "present": |
140 | 157 | String documentPath = call.argument("document"); |
|
0 commit comments