mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-06 02:35:19 +08:00
Changed: Rename UriUtils getUriFilePath() to getUriFilePathWithFragment()
This commit is contained in:
@@ -73,7 +73,7 @@ public class TermuxOpenReceiver extends BroadcastReceiver {
|
||||
}
|
||||
|
||||
// Get full path including fragment (anything after last "#")
|
||||
String filePath = UriUtils.getUriFilePath(data);
|
||||
String filePath = UriUtils.getUriFilePathWithFragment(data);
|
||||
|
||||
final File fileToShare = new File(filePath);
|
||||
if (!(fileToShare.isFile() && fileToShare.canRead())) {
|
||||
|
@@ -351,7 +351,7 @@ public final class TermuxService extends Service implements AppShell.AppShellCli
|
||||
Logger.logVerbose(LOG_TAG, "uri: \"" + executionCommand.executableUri + "\", path: \"" + executionCommand.executableUri.getPath() + "\", fragment: \"" + executionCommand.executableUri.getFragment() + "\"");
|
||||
|
||||
// Get full path including fragment (anything after last "#")
|
||||
executionCommand.executable = UriUtils.getUriFilePath(executionCommand.executableUri);
|
||||
executionCommand.executable = UriUtils.getUriFilePathWithFragment(executionCommand.executableUri);
|
||||
executionCommand.arguments = IntentUtils.getStringArrayExtraIfSet(intent, TERMUX_SERVICE.EXTRA_ARGUMENTS, null);
|
||||
if (executionCommand.inBackground)
|
||||
executionCommand.stdin = IntentUtils.getStringExtraIfSet(intent, TERMUX_SERVICE.EXTRA_STDIN, null);
|
||||
|
@@ -99,7 +99,7 @@ public class TermuxFileReceiverActivity extends Activity {
|
||||
Logger.logVerbose(LOG_TAG, "uri: \"" + dataUri + "\", path: \"" + dataUri.getPath() + "\", fragment: \"" + dataUri.getFragment() + "\"");
|
||||
|
||||
// Get full path including fragment (anything after last "#")
|
||||
String path = UriUtils.getUriFilePath(dataUri);
|
||||
String path = UriUtils.getUriFilePathWithFragment(dataUri);
|
||||
if (DataUtils.isNullOrEmpty(path)) {
|
||||
showErrorDialogAndQuit("File path from data uri is null, empty or invalid.");
|
||||
return;
|
||||
|
@@ -3,6 +3,7 @@ package com.termux.shared.net.uri;
|
||||
import android.net.Uri;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.termux.shared.data.DataUtils;
|
||||
import com.termux.shared.file.FileUtils;
|
||||
@@ -10,7 +11,7 @@ import com.termux.shared.file.FileUtils;
|
||||
public class UriUtils {
|
||||
|
||||
/**
|
||||
* Get the full file path from a {@link Uri}.
|
||||
* Get the full file path from a {@link Uri} including the fragment.
|
||||
*
|
||||
* If the {@link Uri} was created from file path with {@link Uri#parse(String)}, like "am"
|
||||
* command "-d" option does, and the path contained a "#", then anything after it would become
|
||||
@@ -21,10 +22,11 @@ public class UriUtils {
|
||||
* with {@link Uri.Builder#path(String)}, then "#" will automatically be encoded to "%23"
|
||||
* and separate fragment will not exist.
|
||||
*
|
||||
* @param uri The {@link Uri} to get basename from.
|
||||
* @param uri The {@link Uri} to get file path from.
|
||||
* @return Returns the file path if found, otherwise {@code null}.
|
||||
*/
|
||||
public static String getUriFilePath(Uri uri) {
|
||||
@Nullable
|
||||
public static String getUriFilePathWithFragment(Uri uri) {
|
||||
if (uri == null) return null;
|
||||
String path = uri.getPath();
|
||||
if (DataUtils.isNullOrEmpty(path)) return null;
|
||||
@@ -40,12 +42,13 @@ public class UriUtils {
|
||||
* @param withFragment If the {@link Uri} fragment should be included in basename.
|
||||
* @return Returns the file basename if found, otherwise {@code null}.
|
||||
*/
|
||||
@Nullable
|
||||
public static String getUriFileBasename(Uri uri, boolean withFragment) {
|
||||
if (uri == null) return null;
|
||||
|
||||
String path;
|
||||
if (withFragment) {
|
||||
path = getUriFilePath(uri);
|
||||
path = getUriFilePathWithFragment(uri);
|
||||
} else {
|
||||
path = uri.getPath();
|
||||
if (DataUtils.isNullOrEmpty(path)) return null;
|
||||
|
Reference in New Issue
Block a user