|
9 | 9 | import android.content.Context;
|
10 | 10 | import android.content.SharedPreferences;
|
11 | 11 | import android.content.Intent;
|
| 12 | +import android.content.pm.PackageManager; |
12 | 13 | import android.content.res.Configuration;
|
13 | 14 | import android.graphics.Canvas;
|
14 | 15 | import android.graphics.Matrix;
|
@@ -1664,30 +1665,39 @@ public void onExternalResponse(@NonNull GeckoSession geckoSession, @NonNull Geck
|
1664 | 1665 | startDownload(job, true);
|
1665 | 1666 |
|
1666 | 1667 | } else {
|
1667 |
| - showConfirmPrompt(getResources().getString(R.string.download_open_file_unsupported_title), |
1668 |
| - getResources().getString(R.string.download_open_file_unsupported_body), |
1669 |
| - new String[]{ |
1670 |
| - getResources().getString(R.string.download_open_file_unsupported_cancel), |
1671 |
| - getResources().getString(R.string.download_open_file_unsupported_open) |
1672 |
| - }, (index, isChecked) -> { |
1673 |
| - if (index == PromptDialogWidget.POSITIVE) { |
1674 |
| - Uri contentUri = FileProvider.getUriForFile( |
1675 |
| - getContext(), |
1676 |
| - getContext().getApplicationContext().getPackageName() + ".provider", |
1677 |
| - new File(webResponseInfo.uri.substring("file://".length()))); |
1678 |
| - Intent newIntent = new Intent(Intent.ACTION_VIEW); |
1679 |
| - newIntent.setDataAndType(contentUri, webResponseInfo.contentType); |
1680 |
| - newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION); |
1681 |
| - try { |
1682 |
| - getContext().startActivity(newIntent); |
1683 |
| - } catch (ActivityNotFoundException ex) { |
1684 |
| - showAlert( |
1685 |
| - getResources().getString(R.string.download_open_file_error_title), |
1686 |
| - getResources().getString(R.string.download_open_file_error_body), |
1687 |
| - null); |
| 1668 | + Uri contentUri = FileProvider.getUriForFile( |
| 1669 | + getContext(), |
| 1670 | + getContext().getApplicationContext().getPackageName() + ".provider", |
| 1671 | + new File(webResponseInfo.uri.substring("file://".length()))); |
| 1672 | + Intent newIntent = new Intent(Intent.ACTION_VIEW); |
| 1673 | + newIntent.setDataAndType(contentUri, webResponseInfo.contentType); |
| 1674 | + newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION); |
| 1675 | + |
| 1676 | + PackageManager packageManager = getContext().getPackageManager(); |
| 1677 | + if (newIntent.resolveActivity(packageManager) != null) { |
| 1678 | + showConfirmPrompt(getResources().getString(R.string.download_open_file_unsupported_title), |
| 1679 | + getResources().getString(R.string.download_open_file_unsupported_body), |
| 1680 | + new String[]{ |
| 1681 | + getResources().getString(R.string.download_open_file_unsupported_cancel), |
| 1682 | + getResources().getString(R.string.download_open_file_unsupported_open) |
| 1683 | + }, (index, isChecked) -> { |
| 1684 | + if (index == PromptDialogWidget.POSITIVE) { |
| 1685 | + try { |
| 1686 | + getContext().startActivity(newIntent); |
| 1687 | + } catch (ActivityNotFoundException ignored) { |
| 1688 | + showAlert( |
| 1689 | + getResources().getString(R.string.download_open_file_error_title), |
| 1690 | + getResources().getString(R.string.download_open_file_error_body), |
| 1691 | + null); |
| 1692 | + } |
1688 | 1693 | }
|
1689 |
| - } |
1690 |
| - }); |
| 1694 | + }); |
| 1695 | + } else { |
| 1696 | + showAlert( |
| 1697 | + getResources().getString(R.string.download_open_file_error_title), |
| 1698 | + getResources().getString(R.string.download_open_file_open_unsupported_body), |
| 1699 | + null); |
| 1700 | + } |
1691 | 1701 | }
|
1692 | 1702 | }
|
1693 | 1703 |
|
|
0 commit comments