本文整理汇总了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;
}
示例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();
}
示例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);//根据图片路径显示图片
}
示例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;
}
示例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();
}
示例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);
}
示例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);
}
示例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) {
}
}
示例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);
}
}
示例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);
}
}
示例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;
}
}
示例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;
}
示例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;
}
}
示例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());
}
示例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);
}