Skip to content

Commit 0f84921

Browse files
committed
[21864] Ensure launch url can open a document on Android 6+
1 parent 78ae079 commit 0f84921

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

docs/notes/bugfix-21864.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Ensure launch url does open a document on Android 6+

engine/src/java/com/runrev/android/Engine.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,8 @@ public void onUrlError(int p_id, String p_err_msg)
16441644
public void launchUrl(String p_url)
16451645
{
16461646
String t_type = null;
1647-
if (p_url.startsWith("file:"))
1647+
Uri t_uri;
1648+
if (p_url.startsWith("file:") || p_url.startsWith("binfile:"))
16481649
{
16491650
try
16501651
{
@@ -1657,13 +1658,29 @@ public void launchUrl(String p_url)
16571658

16581659
if (t_type == null)
16591660
t_type = URLConnection.guessContentTypeFromName(p_url);
1661+
1662+
// Store the actual path
1663+
String t_path;
1664+
t_path = p_url.substring(p_url.indexOf(":") + 1);
1665+
1666+
// In the new Android permissions model, "file://" and "binfile://" URIs are not allowed
1667+
// for sharing files with other apps. They need to be replaced with "content://" URI and
1668+
// use a FileProvider instead
1669+
t_uri = FileProvider.getProvider(getContext()).addPath(t_path, t_path, t_type, false, ParcelFileDescriptor.MODE_READ_ONLY);
16601670
}
1661-
1671+
else
1672+
{
1673+
t_uri = Uri.parse(p_url);
1674+
}
1675+
16621676
Intent t_view_intent = new Intent(Intent.ACTION_VIEW);
1677+
16631678
if (t_type != null)
1664-
t_view_intent.setDataAndType(Uri.parse(p_url), t_type);
1679+
t_view_intent.setDataAndType(t_uri, t_type);
16651680
else
1666-
t_view_intent.setData(Uri.parse(p_url));
1681+
t_view_intent.setData(t_uri);
1682+
1683+
t_view_intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
16671684
((LiveCodeActivity)getContext()).startActivityForResult(t_view_intent, LAUNCHURL_RESULT);
16681685
}
16691686

0 commit comments

Comments
 (0)