本文整理汇总了Java中android.net.Uri.getEncodedPath方法的典型用法代码示例。如果您正苦于以下问题:Java Uri.getEncodedPath方法的具体用法?Java Uri.getEncodedPath怎么用?Java Uri.getEncodedPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.net.Uri
的用法示例。
在下文中一共展示了Uri.getEncodedPath方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: openAssetFile
import android.net.Uri; //导入方法依赖的package包/类
@Override
public AssetFileDescriptor openAssetFile(Uri uri, String mode)
throws FileNotFoundException {
initIfNecessary();
String path = uri.getEncodedPath();
if ( path.startsWith("/") ) {
path = path.substring(1);
}
return mAPKExtensionFile.getAssetFileDescriptor(path);
}
示例2: getFileForUri
import android.net.Uri; //导入方法依赖的package包/类
public File getFileForUri(Uri uri) {
String path = uri.getEncodedPath();
int splitIndex = path.indexOf(47, 1);
String tag = Uri.decode(path.substring(1, splitIndex));
path = Uri.decode(path.substring(splitIndex + 1));
File root = (File) this.mRoots.get(tag);
if (root == null) {
throw new IllegalArgumentException("Unable to find configured root for " + uri);
}
File file = new File(root, path);
try {
file = file.getCanonicalFile();
if (file.getPath().startsWith(root.getPath())) {
return file;
}
throw new SecurityException("Resolved path jumped beyond configured root");
} catch (IOException e) {
throw new IllegalArgumentException("Failed to resolve canonical path for " + file);
}
}
示例3: query
import android.net.Uri; //导入方法依赖的package包/类
@SuppressLint("NewApi")
@Nullable
@Override
public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder) {
String path = uri.getEncodedPath();
if (!path.startsWith("/font/")
|| selectionArgs == null || selectionArgs[0] == null) {
return null;
}
String name = path.substring("/font/".length());
String[] w = selectionArgs[0].split(",");
int[] weight = new int[w.length];
for (int i = 0; i < w.length; i++) {
weight[i] = Integer.parseInt(w[i]);
}
FontFamily[] families = FontManager.getFontFamily(getContext(), name, weight);
Bundle bundle = new Bundle();
bundle.putParcelableArray("data", families);
AbstractCursor cursor = new SimpleCursor();
cursor.setExtras(bundle);
return cursor;
}
示例4: toLocalUri
import android.net.Uri; //导入方法依赖的package包/类
@Override
public LocalFilesystemURL toLocalUri(Uri inputURL) {
if (!"content".equals(inputURL.getScheme())) {
return null;
}
String subPath = inputURL.getEncodedPath();
if (subPath.length() > 0) {
subPath = subPath.substring(1);
}
Uri.Builder b = new Uri.Builder()
.scheme(LocalFilesystemURL.FILESYSTEM_PROTOCOL)
.authority("localhost")
.path(name)
.appendPath(inputURL.getAuthority());
if (subPath.length() > 0) {
b.appendEncodedPath(subPath);
}
Uri localUri = b.encodedQuery(inputURL.getEncodedQuery())
.encodedFragment(inputURL.getEncodedFragment())
.build();
return LocalFilesystemURL.parse(localUri);
}
示例5: getFileForUri
import android.net.Uri; //导入方法依赖的package包/类
@Override
public File getFileForUri(Uri uri) {
String path = uri.getEncodedPath();
final int splitIndex = path.indexOf('/', 1);
final String tag = Uri.decode(path.substring(1, splitIndex));
path = Uri.decode(path.substring(splitIndex + 1));
final File root = mRoots.get(tag);
if (root == null) {
throw new IllegalArgumentException("Unable to find configured root for " + uri );
}
File file = new File(root, path);
try {
file = file.getCanonicalFile();
} catch (IOException e) {
throw new IllegalArgumentException("Failed to resolve canonical path for " + file);
}
if (!file.getPath().startsWith(root.getPath())) {
throw new SecurityException("Resolved path jumped beyond configured root");
}
return file;
}
示例6: getFileForUri
import android.net.Uri; //导入方法依赖的package包/类
@Override
public File getFileForUri(Uri uri) {
String path = uri.getEncodedPath();
final int splitIndex = path.indexOf('/', 1);
final String tag = Uri.decode(path.substring(1, splitIndex));
path = Uri.decode(path.substring(splitIndex + 1));
final File root = mRoots.get(tag);
if (root == null) {
throw new IllegalArgumentException("Unable to find configured root for " + uri);
}
File file = new File(root, path);
try {
file = file.getCanonicalFile();
} catch (IOException e) {
throw new IllegalArgumentException("Failed to resolve canonical path for " + file);
}
if (!file.getPath().startsWith(root.getPath())) {
throw new SecurityException("Resolved path jumped beyond configured root");
}
return file;
}
示例7: a
import android.net.Uri; //导入方法依赖的package包/类
public static MLinkResult a(Uri uri, Uri uri2) {
if (uri2 == null) {
return new MLinkResult();
}
String scheme = uri2.getScheme();
String host = uri2.getHost();
int port = uri2.getPort();
String encodedPath = uri2.getEncodedPath();
String encodedQuery = uri2.getEncodedQuery();
String scheme2 = uri.getScheme();
String host2 = uri.getHost();
int port2 = uri.getPort();
String encodedPath2 = uri.getEncodedPath();
String encodedQuery2 = uri.getEncodedQuery();
if (n.a(scheme, scheme2) && n.a(host, host2) && port == port2) {
return a(encodedPath, encodedPath2, a(encodedQuery2, encodedQuery));
}
return new MLinkResult();
}
示例8: uriToPath
import android.net.Uri; //导入方法依赖的package包/类
public static String uriToPath(Uri uri) {
// URI looks like this content://sk.momosi.fuelup.file.provider/external_files/Pictures/FuelUp/JPEF....
if (!AUTHORITY.equals(uri.getAuthority())) {
throw new IllegalArgumentException("This URI is not provided by " + GenericFileProvider.class.getSimpleName());
}
String path = uri.getEncodedPath();
path = path.replace("/"+ EXTERNAL_PATH, Environment.getExternalStorageDirectory().getAbsolutePath());
return path;
}
示例9: openFile
import android.net.Uri; //导入方法依赖的package包/类
@Nullable
@Override
public ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode) throws FileNotFoundException {
String path = uri.getEncodedPath();
if (!path.startsWith("/file/")) {
return null;
}
return FontManager.getParcelFileDescriptor(getContext(), path.substring("/file/".length()));
}
示例10: parseOwnUri
import android.net.Uri; //导入方法依赖的package包/类
/**
* 提供的Uri 解析出文件绝对路径
*
* @param uri
* @return
*/
public static String parseOwnUri(Uri uri, Context context,File cameraFile) {
if (uri == null) return "";
String path;
if (TextUtils.equals(uri.getAuthority(), getFileProviderName(context))) {
if (cameraFile != null){
return cameraFile.getAbsolutePath();
}else{
path = new File(Environment.getExternalStorageDirectory(), uri.getPath().replace("my_external/", "")).getAbsolutePath();
}
} else {
path = uri.getEncodedPath();
}
return path;
}
示例11: convertToRelativePath
import android.net.Uri; //导入方法依赖的package包/类
public static String convertToRelativePath(final Uri absoluteUri, final Uri relativeToUri)
{
if (!absoluteUri.getScheme().equals(relativeToUri.getScheme()))
{
return null;
}
String absolutePath = null, relativeTo = null;
if (isContentUri(absoluteUri))
{
absolutePath = AdapterDocuments.getPath(absoluteUri, true);
relativeTo = AdapterDocuments.getPath(relativeToUri, true);
}
else
{
absolutePath = absoluteUri.getEncodedPath();
relativeTo = relativeToUri.getEncodedPath();
}
if (absolutePath == null || relativeTo == null)
{
return null;
}
// Thanks to:
// http://mrpmorris.blogspot.com/2007/05/convert-absolute-path-to-relative-path.html
absolutePath = absolutePath.replaceAll("\\\\", "/");
relativeTo = relativeTo.replaceAll("\\\\", "/");
StringBuilder relativePath = null;
if (!absolutePath.equals(relativeTo))
{
String[] absoluteDirectories = absolutePath.split("/");
String[] relativeDirectories = relativeTo.split("/");
//Get the shortest of the two paths
int length = absoluteDirectories.length < relativeDirectories.length ? absoluteDirectories.length
: relativeDirectories.length;
//Use to determine where in the loop we exited
int lastCommonRoot = -1;
int index;
//Find common root
for (index = 0; index < length; index++)
{
if (absoluteDirectories[index].equals(relativeDirectories[index]))
{
lastCommonRoot = index;
}
else
{
break;
//If we didn't find a common prefix then throw
}
}
if (lastCommonRoot != -1)
{
//Build up the relative path
relativePath = new StringBuilder();
//Add on the ..
for (index = lastCommonRoot + 1; index < absoluteDirectories.length; index++)
{
if (absoluteDirectories[index].length() > 0)
{
relativePath.append("../");
}
}
for (index = lastCommonRoot + 1; index < relativeDirectories.length - 1; index++)
{
relativePath.append(relativeDirectories[index] + "/");
}
relativePath.append(relativeDirectories[relativeDirectories.length - 1]);
}
}
return relativePath == null ? null : relativePath.toString();
}