|
4 | 4 | import android.app.Dialog; |
5 | 5 | import android.content.Context; |
6 | 6 | import android.content.DialogInterface; |
| 7 | +import android.content.res.Resources; |
7 | 8 | import android.graphics.Color; |
8 | 9 | import android.graphics.Point; |
9 | 10 | import android.graphics.Rect; |
@@ -200,9 +201,12 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c |
200 | 201 | applyWindowGravity(getDialog().getWindow(), "onCreateView"); |
201 | 202 | } |
202 | 203 |
|
203 | | - webView = new IterableWebView(getContext()); |
| 204 | + webView = createWebViewSafely(getContext()); |
| 205 | + if (webView == null) { |
| 206 | + dismissAllowingStateLoss(); |
| 207 | + return null; |
| 208 | + } |
204 | 209 | webView.setId(R.id.webView); |
205 | | - |
206 | 210 | webView.createWithHtml(this, htmlString); |
207 | 211 |
|
208 | 212 | if (orientationListener == null) { |
@@ -324,7 +328,9 @@ public void onSaveInstanceState(@NonNull Bundle outState) { |
324 | 328 | */ |
325 | 329 | @Override |
326 | 330 | public void onStop() { |
327 | | - orientationListener.disable(); |
| 331 | + if (orientationListener != null) { |
| 332 | + orientationListener.disable(); |
| 333 | + } |
328 | 334 |
|
329 | 335 | super.onStop(); |
330 | 336 | } |
@@ -747,6 +753,18 @@ InAppLayout getInAppLayout(Rect padding) { |
747 | 753 | return InAppLayout.CENTER; |
748 | 754 | } |
749 | 755 | } |
| 756 | + |
| 757 | + private IterableWebView createWebViewSafely(Context context) { |
| 758 | + try { |
| 759 | + return new IterableWebView(context); |
| 760 | + } catch (Resources.NotFoundException e) { |
| 761 | + IterableLogger.e(TAG, "Failed to create WebView - system WebView resource issue", e); |
| 762 | + return null; |
| 763 | + } catch (RuntimeException e) { |
| 764 | + IterableLogger.e(TAG, "Failed to create WebView - unexpected error", e); |
| 765 | + return null; |
| 766 | + } |
| 767 | + } |
750 | 768 | } |
751 | 769 |
|
752 | 770 | enum InAppLayout { |
|
0 commit comments