Skip to content

Commit a4df589

Browse files
committed
Move check for path starting with slash in getUriStringForFilePath()
1 parent 235fa59 commit a4df589

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,18 +2047,7 @@ public void showCamera()
20472047
return;
20482048
}
20492049

2050-
// getPath() returns a path starting with /, e.g. /storage/emulated/0/Android/data/<app_id>/cache/..
2051-
// This path is appended to content://<app_id>.fileprovider/share/, resulting in an URI like:
2052-
//
2053-
// content://<app_id>.fileprovider//storage/emulated/0/Android/data/<app_id>/cache/..
2054-
//
2055-
// This is not a problem in general, but in _some_ devices (e.g. Huawei nova e3) this URI is
2056-
// normalized to:
2057-
//
2058-
// content://<app_id>.fileprovider/storage/emulated/0/Android/data/<app_id>/cache/..
2059-
//
2060-
// This results in the URI not being found. So use .substring(1) to remove the first slash
2061-
String t_path = m_temp_image_file.getPath().substring(1);
2050+
String t_path = m_temp_image_file.getPath();
20622051

20632052
Uri t_uri;
20642053
t_uri = FileProvider.getProvider(getContext()).addPath(t_path, t_path, "image/jpeg", true, ParcelFileDescriptor.MODE_WRITE_ONLY);

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@ private String getFilePath(String p_path)
8787

8888
private String getUriStringForFilePath(String p_path)
8989
{
90+
// If p_path begins with slash, then the resulting URI will be like e.g. :
91+
92+
// content://<app_id>.fileprovider//storage/emulated/0/Android/data/<app_id>/cache/..
93+
//
94+
// This is not a problem in general, but in _some_ devices (e.g. Huawei nova e3) this URI is
95+
// normalized to:
96+
//
97+
// content://<app_id>.fileprovider/storage/emulated/0/Android/data/<app_id>/cache/..
98+
//
99+
// This results in the URI not being found. So use .substring(1) to remove the first slash, if any
100+
if (p_path.charAt(0) == '/')
101+
p_path = p_path.substring(1);
90102
return m_content_uri_base + "/" + p_path;
91103
}
92104

0 commit comments

Comments
 (0)