当前位置: 首页>>代码示例>>Java>>正文


Java Uri.getPath方法代码示例

本文整理汇总了Java中android.net.Uri.getPath方法的典型用法代码示例。如果您正苦于以下问题:Java Uri.getPath方法的具体用法?Java Uri.getPath怎么用?Java Uri.getPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.net.Uri的用法示例。


在下文中一共展示了Uri.getPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: mapUriToFile

import android.net.Uri; //导入方法依赖的package包/类
/**
 * Returns a File that points to the resource, or null if the resource
 * is not on the local filesystem.
 */
public File mapUriToFile(Uri uri) {
    assertBackgroundThread();
    switch (getUriType(uri)) {
        case URI_TYPE_FILE:
            return new File(uri.getPath());
        case URI_TYPE_CONTENT: {
            Cursor cursor = contentResolver.query(uri, LOCAL_FILE_PROJECTION, null, null, null);
            if (cursor != null) {
                try {
                    int columnIndex = cursor.getColumnIndex(LOCAL_FILE_PROJECTION[0]);
                    if (columnIndex != -1 && cursor.getCount() > 0) {
                        cursor.moveToFirst();
                        String realPath = cursor.getString(columnIndex);
                        if (realPath != null) {
                            return new File(realPath);
                        }
                    }
                } finally {
                    cursor.close();
                }
            }
        }
    }
    return null;
}
 
开发者ID:aabognah,项目名称:LoRaWAN-Smart-Parking,代码行数:30,代码来源:CordovaResourceApi.java

示例2: handleImage

import android.net.Uri; //导入方法依赖的package包/类
private void handleImage(Uri uri){
    String imagePath = null;
    if(DocumentsContract.isDocumentUri(getActivity(), uri)){
        String docId = DocumentsContract.getDocumentId(uri);
        if("com.android.providers.media.documents".equals(uri.getAuthority())){
            String id = docId.split(":")[1];
            String selection = MediaStore.Images.Media._ID+"="+id;
            imagePath = getImagePath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection);

        }
        else if("com.android.providers.downloads.documents".equals(uri.getAuthority())){
            Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(docId));
            imagePath = getImagePath(contentUri, null);
        }
    }
    else if("content".equalsIgnoreCase(uri.getScheme())){
        imagePath = getImagePath(uri, null);
    }
    else if("file".equalsIgnoreCase(uri.getScheme())){
        imagePath = uri.getPath();
    }
    filePath = imagePath;
    Log.i(TAG, "handleImage: Album filepath"+filePath);
    getQiniuUpToken();
}
 
开发者ID:shawnsky,项目名称:RantApp,代码行数:26,代码来源:SelectPhotoFragment.java

示例3: handleImageOnKitKat

import android.net.Uri; //导入方法依赖的package包/类
@TargetApi(19)
private void handleImageOnKitKat(Intent data){
    String imagePath = null;
    Uri uri = data.getData();
    if(DocumentsContract.isDocumentUri(this,uri)){
        String docId = DocumentsContract.getDocumentId(uri);
        if("com.android.provider.media,documents".equals(uri.getAuthority())){
            String id = docId.split(":")[1];
            String selection = MediaStore.Images.Media._ID + "=" + id;
            imagePath = getImagePath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,selection);
        }else if("com.android.provider.downloads.documents".equals(uri.getAuthority())){
            Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"),Long.valueOf(docId));
                    imagePath = getImagePath(contentUri,null);
        }
    }else if("content".equalsIgnoreCase(uri.getScheme())){
        imagePath = getImagePath(uri,null);
    }else if("file".equalsIgnoreCase(uri.getScheme())){
        imagePath = uri.getPath();
    }
    displayImage(imagePath);//根据图片路径显示图片
}
 
开发者ID:wangyufei1006,项目名称:CameraAlbumTest,代码行数:22,代码来源:MainActivity.java

示例4: getRotationFromCamera

import android.net.Uri; //导入方法依赖的package包/类
private static int getRotationFromCamera(Context context, Uri imageFile) {
    int rotate = 0;
    try {

        context.getContentResolver().notifyChange(imageFile, null);
        ExifInterface exif = new ExifInterface(imageFile.getPath());
        int orientation = exif.getAttributeInt(
                ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_NORMAL);

        switch (orientation) {
            case ExifInterface.ORIENTATION_ROTATE_270:
                rotate = 270;
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                rotate = 180;
                break;
            case ExifInterface.ORIENTATION_ROTATE_90:
                rotate = 90;
                break;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return rotate;
}
 
开发者ID:AppHero2,项目名称:Raffler-Android,代码行数:27,代码来源:ImagePicker.java

示例5: setVideoURI

import android.net.Uri; //导入方法依赖的package包/类
public void setVideoURI(Uri uri, Map<String, String> extraMap) {
    reset();
    mUri = uri;
    mExtraMap = extraMap;
    String scheme = mUri.getScheme();
    mIsLocalVideo = false;
    if (scheme == null || scheme.equals("file")) {
        mIsLocalVideo = true;
    } else {
        if (scheme.equals("content")) {
            try {
                if (Integer.parseInt(mUri.getLastPathSegment()) <= ArchosMediaCommon.SCANNED_ID_OFFSET)
                    mIsLocalVideo = true;
            } catch (NumberFormatException e) {}
        }
    }

    if (uri.getPath() != null) {
        // FIXME: "smb://hello/world" .getPath() will return something like "hello/world".
        // fixing this the quick way will break all sort of things
        mVideoMetadata.setFile(uri.getPath());
    }
    if (DBG) Log.d(TAG, "setVideoURI: " + uri);
    openVideo();
}
 
开发者ID:archos-sa,项目名称:aos-Video,代码行数:26,代码来源:Player.java

示例6: onNewIntent

import android.net.Uri; //导入方法依赖的package包/类
@Override
protected void onNewIntent(Intent intent) {
    getViews();
    setViews();
    setListeners();
    Uri data = intent.getData();
    if(data!=null) {
        mPdfPath = data.getPath();
        displayPdf(data);
    }else {
        if(intent.hasExtra("path")) {
            mPdfPath = intent.getStringExtra("path");
            pageNumber = intent.getIntExtra("pageNum",0);
            Uri uri = Uri.parse("file://" + mPdfPath);
            displayPdf(uri);
        }
    }

    super.onNewIntent(intent);
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:21,代码来源:PdfPreviewActivity.java

示例7: getFileWithUri

import android.net.Uri; //导入方法依赖的package包/类
/**
 * 通过URI获取文件
 * @param uri
 * @param activity
 * @return
 * Author JPH
 * Date 2016/10/25
 */
public static File getFileWithUri(Uri uri, Activity activity) {
    String picturePath = null;
    String scheme=uri.getScheme();
    if (ContentResolver.SCHEME_CONTENT.equals(scheme)){
        String[] filePathColumn = {MediaStore.Images.Media.DATA};
        Cursor cursor = activity.getContentResolver().query(uri,
                filePathColumn, null, null, null);//从系统表中查询指定Uri对应的照片
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        if(columnIndex>=0){
            picturePath = cursor.getString(columnIndex);  //获取照片路径
        }else if(TextUtils.equals(uri.getAuthority(),TConstant.getFileProviderName(activity))){
            picturePath=parseOwnUri(activity,uri);
        }
        cursor.close();
    }else if (ContentResolver.SCHEME_FILE.equals(scheme)){
        picturePath=uri.getPath();
    }
    return TextUtils.isEmpty(picturePath)? null:new File(picturePath);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:29,代码来源:TUriParse.java

示例8: playFile

import android.net.Uri; //导入方法依赖的package包/类
/**
 * @param context The {@link Context} to use
 * @param uri     The source of the file
 */
public static void playFile(final Context context, final Uri uri) {
    if (uri == null || mService == null) {
        return;
    }

    // If this is a file:// URI, just use the path directly instead
    // of going through the open-from-filedescriptor codepath.
    String filename;
    String scheme = uri.getScheme();
    if ("file".equals(scheme)) {
        filename = uri.getPath();
    } else {
        filename = uri.toString();
    }

    try {
        mService.stop();
        mService.openFile(filename);
        mService.play();
    } catch (final RemoteException ignored) {
    }
}
 
开发者ID:komamj,项目名称:KomaMusic,代码行数:27,代码来源:MusicUtils.java

示例9: sendPicByUri

import android.net.Uri; //导入方法依赖的package包/类
public static void sendPicByUri(Context context, Handler handler,
		Uri selectedImage, ZhiChiInitModeBase initModel,final ListView lv_message,
								final SobotMsgAdapter messageAdapter) {
	if(initModel == null){
		return;
	}
	String picturePath = ImageUtils.getPath(context, selectedImage);
	LogUtils.i("picturePath:" + picturePath);
	if (!TextUtils.isEmpty(picturePath)) {
		sendPicLimitBySize(picturePath, initModel.getCid(),
				initModel.getUid(), handler, context, lv_message,messageAdapter);
	} else {
		File file = new File(selectedImage.getPath());
		if (!file.exists()) {
			ToastUtil.showToast(context,"找不到图片");
			return;
		}
		sendPicLimitBySize(file.getAbsolutePath(),
				initModel.getCid(), initModel.getUid(), handler, context, lv_message,messageAdapter);
	}
}
 
开发者ID:fengdongfei,项目名称:CXJPadProject,代码行数:22,代码来源:ChatUtils.java

示例10: defaultFile

import android.net.Uri; //导入方法依赖的package包/类
private void defaultFile(String text)
{
    File documents = new
    File(Environment.getExternalStorageDirectory(), DOCUMENTS);
    file = new File(documents, EDIT_FILE);

    Uri uri = Uri.fromFile(file);
    path = uri.getPath();

    if (file.exists())
    {
        readFile(uri);
        toAppend = text;
    }

    else
    {
        if (text != null)
            textView.append(text);

        String title = uri.getLastPathSegment();
        setTitle(title);
    }
}
 
开发者ID:billthefarmer,项目名称:editor,代码行数:25,代码来源:Editor.java

示例11: ensureBookIsInCollection

import android.net.Uri; //导入方法依赖的package包/类
public String ensureBookIsInCollection(Context context, Uri bookUri) {
    if (bookUri.getPath().indexOf(mLocalBooksDirectory.getAbsolutePath()) >= 0)
        return bookUri.getPath();
    BloomFileReader fileReader = new BloomFileReader(context, bookUri);
    String name = fileReader.bookNameIfValid();
    if(name == null)
        return null;

    Log.d("BloomReader", "Moving book into Bloom directory");
    String destination = mLocalBooksDirectory.getAbsolutePath() + File.separator + name;
    boolean copied = IOUtilities.copyFile(context, bookUri, destination);
    if(copied){
        // We assume that they will be happy with us removing from where ever the file was,
        // so long as it is on the same device (e.g. not coming from an sd card they plan to pass
        // around the room).
        if(!IOUtilities.seemToBeDifferentVolumes(bookUri.getPath(),destination)) {
            (new File(bookUri.getPath())).delete();
        }
        // we wouldn't have it in our list that we display yet, so make an entry there
        addBook(destination, true);
        return destination;
    } else{
        return null;
    }
}
 
开发者ID:BloomBooks,项目名称:BloomReader,代码行数:26,代码来源:BookCollection.java

示例12: getRealFilePath

import android.net.Uri; //导入方法依赖的package包/类
public String getRealFilePath(Uri uri)
  {
String path = uri.getPath();
String[] pathArray = path.split(":");
String fileName = pathArray[pathArray.length - 1];
return Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + fileName;
  }
 
开发者ID:stytooldex,项目名称:stynico,代码行数:8,代码来源:Viewhtml.java

示例13: getRealPathFromURI

import android.net.Uri; //导入方法依赖的package包/类
static String getRealPathFromURI(Context context, Uri contentUri) {
    Cursor cursor = context.getContentResolver().query(contentUri, null, null, null, null);
    if (cursor == null) {
        return contentUri.getPath();
    } else {
        cursor.moveToFirst();
        int index = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
        String realPath = cursor.getString(index);
        cursor.close();
        return realPath;
    }
}
 
开发者ID:liu-xiao-dong,项目名称:JD-Test,代码行数:13,代码来源:FileUtil.java

示例14: toLocalUri

import android.net.Uri; //导入方法依赖的package包/类
@Override
public LocalFilesystemURL toLocalUri(Uri inputURL) {
    if (!"file".equals(inputURL.getScheme())) {
        return null;
    }
    File f = new File(inputURL.getPath());
    // Removes and duplicate /s (e.g. file:///a//b/c)
    Uri resolvedUri = Uri.fromFile(f);
    String rootUriNoTrailingSlash = rootUri.getEncodedPath();
    rootUriNoTrailingSlash = rootUriNoTrailingSlash.substring(0, rootUriNoTrailingSlash.length() - 1);
    if (!resolvedUri.getEncodedPath().startsWith(rootUriNoTrailingSlash)) {
        return null;
    }
    String subPath = resolvedUri.getEncodedPath().substring(rootUriNoTrailingSlash.length());
    // Strip leading slash
    if (!subPath.isEmpty()) {
        subPath = subPath.substring(1);
    }
    Uri.Builder b = new Uri.Builder()
        .scheme(LocalFilesystemURL.FILESYSTEM_PROTOCOL)
        .authority("localhost")
        .path(name);
    if (!subPath.isEmpty()) {
        b.appendEncodedPath(subPath);
    }
    if (f.isDirectory()) {
        // Add trailing / for directories.
        b.appendEncodedPath("");
    }
    return LocalFilesystemURL.parse(b.build());
}
 
开发者ID:rodrigonsh,项目名称:alerta-fraude,代码行数:32,代码来源:LocalFilesystem.java

示例15: getSafeUri

import android.net.Uri; //导入方法依赖的package包/类
/**
 * Copies the APK into private data directory of F-Droid and returns a "file" or "content" Uri
 * to be used for installation.
 */
public static Uri getSafeUri(Context context, Uri localApkUri, Apk expectedApk, boolean useContentUri)
        throws IOException {
    File apkFile = new File(localApkUri.getPath());
    SanitizedFile tempApkFile = ApkCache.copyApkFromCacheToFiles(context, apkFile, expectedApk);
    return getSafeUri(context, tempApkFile, useContentUri);

}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:12,代码来源:ApkFileProvider.java


注:本文中的android.net.Uri.getPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。