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


Java ParcelFileDescriptor.open方法代码示例

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


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

示例1: openImageThumbnailCleared

import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
protected ParcelFileDescriptor openImageThumbnailCleared(long id, CancellationSignal signal)
        throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();

    Cursor cursor = null;
    try {
        cursor = resolver.query(Images.Thumbnails.EXTERNAL_CONTENT_URI,
                ImageThumbnailQuery.PROJECTION, Images.Thumbnails.IMAGE_ID + "=" + id, null,
                null);
        if (cursor.moveToFirst()) {
            final String data = cursor.getString(ImageThumbnailQuery._DATA);
            return ParcelFileDescriptor.open(
                    new File(data), ParcelFileDescriptor.MODE_READ_ONLY);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
    }
    return null;
}
 
开发者ID:gigabytedevelopers,项目名称:FireFiles,代码行数:20,代码来源:StorageProvider.java

示例2: openAudioThumbnailCleared

import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
protected ParcelFileDescriptor openAudioThumbnailCleared(long id, CancellationSignal signal)
        throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();

    Cursor cursor = null;
    try {
        cursor = resolver.query(Audio.Albums.EXTERNAL_CONTENT_URI,
        		AudioThumbnailQuery.PROJECTION, Audio.Albums._ID + "=" + id,
                null, null);
        if (cursor.moveToFirst()) {
            final String data = cursor.getString(AudioThumbnailQuery._DATA);
            return ParcelFileDescriptor.open(
                    new File(data), ParcelFileDescriptor.MODE_READ_ONLY);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
    }
    return null;
}
 
开发者ID:gigabytedevelopers,项目名称:FireFiles,代码行数:20,代码来源:StorageProvider.java

示例3: openFile

import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
@Override
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
  Log.w(TAG, "openFile(" + uri + ", " + mode + ")");

  switch (uriMatcher.match(uri)) {
  case SINGLE_ROW:
    Log.w(TAG, "Fetching message body for a single row...");
    File tmpFile = getFile(uri);

    final int fileMode;
    switch (mode) {
    case "w": fileMode = ParcelFileDescriptor.MODE_TRUNCATE |
                         ParcelFileDescriptor.MODE_CREATE   |
                         ParcelFileDescriptor.MODE_WRITE_ONLY; break;
    case "r": fileMode = ParcelFileDescriptor.MODE_READ_ONLY;  break;
    default:  throw new IllegalArgumentException("requested file mode unsupported");
    }

    Log.w(TAG, "returning file " + tmpFile.getAbsolutePath());
    return ParcelFileDescriptor.open(tmpFile, fileMode);
  }

  throw new FileNotFoundException("Request for bad message.");
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:25,代码来源:MmsBodyProvider.java

示例4: FileDescriptorFactory

import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
public FileDescriptorFactory() {
  super(new FileOpener<ParcelFileDescriptor>() {
    @Override
    public ParcelFileDescriptor open(File file) throws FileNotFoundException {
      return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
    }

    @Override
    public void close(ParcelFileDescriptor parcelFileDescriptor) throws IOException {
      parcelFileDescriptor.close();
    }

    @Override
    public Class<ParcelFileDescriptor> getDataClass() {
      return ParcelFileDescriptor.class;
    }
  });
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:FileLoader.java

示例5: newUploadStagingResourceWithImageRequest

import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
/**
 * Creates a new Request configured to upload an image to create a staging resource. Staging
 * resources allow you to post binary data such as images, in preparation for a post of an Open
 * Graph object or action which references the image. The URI returned when uploading a staging
 * resource may be passed as the image property for an Open Graph object or action.
 *
 * @param accessToken the access token to use, or null
 * @param file        the file containing the image to upload
 * @param callback    a callback that will be called when the request is completed to handle
 *                    success or error conditions
 * @return a Request that is ready to execute
 * @throws FileNotFoundException
 */
public static GraphRequest newUploadStagingResourceWithImageRequest(
        AccessToken accessToken,
        File file,
        Callback callback
) throws FileNotFoundException {
    ParcelFileDescriptor descriptor =
            ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
    GraphRequest.ParcelableResourceWithMimeType<ParcelFileDescriptor> resourceWithMimeType =
            new GraphRequest.ParcelableResourceWithMimeType<>(descriptor, "image/png");
    Bundle parameters = new Bundle(1);
    parameters.putParcelable(STAGING_PARAM, resourceWithMimeType);

    return new GraphRequest(
            accessToken,
            MY_STAGING_RESOURCES,
            parameters,
            HttpMethod.POST,
            callback);
}
 
开发者ID:eviltnan,项目名称:kognitivo,代码行数:33,代码来源:ShareInternalUtility.java

示例6: openFile

import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
@Override
public android.os.ParcelFileDescriptor openFile(android.net.Uri uri, java.lang.String mode)
        throws java.io.FileNotFoundException {

    Pair<UUID, String> callIdAndAttachmentName = parseCallIdAndAttachmentName(uri);
    if (callIdAndAttachmentName == null) {
        throw new FileNotFoundException();
    }

    try {
        File file = dataSource.openAttachment(callIdAndAttachmentName.first, callIdAndAttachmentName.second);

        return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
    } catch (FileNotFoundException exception) {
        Log.e(TAG, "Got unexpected exception:" + exception);
        throw exception;
    }
}
 
开发者ID:MobileDev418,项目名称:chat-sdk-android-push-firebase,代码行数:19,代码来源:NativeAppCallContentProvider.java

示例7: getAssetFileDescriptor

import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
public AssetFileDescriptor getAssetFileDescriptor() {
    if (mMethod == kCompressStored) {
        ParcelFileDescriptor pfd;
        try {
            pfd = ParcelFileDescriptor.open(mFile, ParcelFileDescriptor.MODE_READ_ONLY);
            return new AssetFileDescriptor(pfd, getOffset(), mUncompressedLength);
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    return null;
}
 
开发者ID:12d,项目名称:react-native-videoplayer,代码行数:14,代码来源:ZipResourceFile.java

示例8: openAssetFile

import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
/**
 * Opens an asset file for an URI.
 *
 * Called by {@link ContentResolver#openAssetFileDescriptor(Uri, String)} or
 * {@link ContentResolver#openInputStream(Uri)} from a client requesting a
 * dictionary.
 * @see ContentProvider#openAssetFile(Uri, String)
 *
 * @param uri the URI the file is for.
 * @param mode the mode to read the file. MUST be "r" for readonly.
 * @return the descriptor, or null if the file is not found or if mode is not equals to "r".
 */
@Override
public AssetFileDescriptor openAssetFile(final Uri uri, final String mode) {
    if (null == mode || !"r".equals(mode)) return null;

    final int match = matchUri(uri);
    if (DICTIONARY_V1_DICT_INFO != match && DICTIONARY_V2_DATAFILE != match) {
        // Unsupported URI for openAssetFile
        Log.w(TAG, "Unsupported URI for openAssetFile : " + uri);
        return null;
    }
    final String wordlistId = uri.getLastPathSegment();
    final String clientId = getClientId(uri);
    final ContentValues wordList = getWordlistMetadataForWordlistId(clientId, wordlistId);

    if (null == wordList) return null;

    try {
        final int status = wordList.getAsInteger(MetadataDbHelper.STATUS_COLUMN);
        if (MetadataDbHelper.STATUS_DELETING == status) {
            // This will return an empty file (R.raw.empty points at an empty dictionary)
            // This is how we "delete" the files. It allows Android Keyboard to fake deleting
            // a default dictionary - which is actually in its assets and can't be really
            // deleted.
            final AssetFileDescriptor afd = getContext().getResources().openRawResourceFd(
                    R.raw.empty);
            return afd;
        }
        final String localFilename =
                wordList.getAsString(MetadataDbHelper.LOCAL_FILENAME_COLUMN);
        final File f = getContext().getFileStreamPath(localFilename);
        final ParcelFileDescriptor pfd =
                ParcelFileDescriptor.open(f, ParcelFileDescriptor.MODE_READ_ONLY);
        return new AssetFileDescriptor(pfd, 0, pfd.getStatSize());
    } catch (FileNotFoundException e) {
        // No file : fall through and return null
    }
    return null;
}
 
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:51,代码来源:DictionaryProvider.java

示例9: openFile

import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
@Override
public ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode) throws FileNotFoundException {
  MasterSecret masterSecret = KeyCachingService.getMasterSecret(getContext());
  Log.w(TAG, "openFile() called!");

  if (masterSecret == null) {
    Log.w(TAG, "masterSecret was null, abandoning.");
    return null;
  }

  switch (uriMatcher.match(uri)) {
  case SINGLE_ROW:
    Log.w(TAG, "Parting out a single row...");
    try {
      PartUriParser        partUri = new PartUriParser(uri);
      File                 tmpFile = copyPartToTemporaryFile(masterSecret, partUri.getPartId());
      ParcelFileDescriptor pdf     = ParcelFileDescriptor.open(tmpFile, ParcelFileDescriptor.MODE_READ_ONLY);

      if (!tmpFile.delete()) {
        Log.w(TAG, "Failed to delete temp file.");
      }

      return pdf;
    } catch (IOException ioe) {
      Log.w(TAG, ioe);
      throw new FileNotFoundException("Error opening file");
    }
  }

  throw new FileNotFoundException("Request for bad part.");
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:32,代码来源:PartProvider.java

示例10: openDocument

import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
@Override
public ParcelFileDescriptor openDocument(
        String documentId, String mode, CancellationSignal signal)
        throws FileNotFoundException {
    final File file = getFileForDocId(documentId);
    return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);//ParcelFileDescriptor.parseMode(mode));
}
 
开发者ID:medalionk,项目名称:simple-share-android,代码行数:8,代码来源:HeatMapProvider.java

示例11: createForParcelFileDescriptor

import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
/**
 * Creates a DocumentsArchive instance for opening, browsing and accessing
 * documents within the archive passed as a file descriptor.
 *
 * <p>Note, that this method should be used only if the document does not exist
 * on the local storage. A snapshot file will be created, which may be slower
 * and consume significant resources, in contrast to using
 * {@see createForLocalFile(Context, File, String, char, Uri}.
 *
 * @param context Context of the provider.
 * @param descriptor File descriptor for the archive's contents.
 * @param documentId ID of the archive document.
 * @param idDelimiter Delimiter for constructing IDs of documents within the archive.
 *            The delimiter must never be used for IDs of other documents.
 * @param Uri notificationUri Uri for notifying that the archive file has changed.
 * @see createForLocalFile(Context, File, String, char, Uri)
 */
public static DocumentArchive createForParcelFileDescriptor(
        Context context, ParcelFileDescriptor descriptor, String documentId,
        char idDelimiter, @Nullable Uri notificationUri)
        throws IOException {
    File snapshotFile = null;
    try {
        // Create a copy of the archive, as ZipFile doesn't operate on streams.
        // Moreover, ZipInputStream would be inefficient for large files on
        // pipes.
        snapshotFile = File.createTempFile("android.support.provider.snapshot{",
                "}.zip", context.getCacheDir());

        try {
            final FileOutputStream outputStream =
                    new ParcelFileDescriptor.AutoCloseOutputStream(
                            ParcelFileDescriptor.open(
                                    snapshotFile, ParcelFileDescriptor.MODE_WRITE_ONLY));
            final ParcelFileDescriptor.AutoCloseInputStream inputStream =
                    new ParcelFileDescriptor.AutoCloseInputStream(descriptor);
            final byte[] buffer = new byte[32 * 1024];
            int bytes;
            while ((bytes = inputStream.read(buffer)) != -1) {
                outputStream.write(buffer, 0, bytes);
            }
            outputStream.flush();
            return new DocumentArchive(context, snapshotFile, documentId, idDelimiter,
                    notificationUri);
        } catch (Exception e){
            CrashReportingManager.logException(e);
            return null;
        }
    } finally {
        // On UNIX the file will be still available for processes which opened it, even
        // after deleting it. Remove it ASAP, as it won't be used by anyone else.
        if (snapshotFile != null) {
            snapshotFile.delete();
        }
    }
}
 
开发者ID:gigabytedevelopers,项目名称:FireFiles,代码行数:57,代码来源:DocumentArchive.java

示例12: openDocument

import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
@Override
public ParcelFileDescriptor openDocument(
        String documentId, String mode, CancellationSignal signal)
        throws FileNotFoundException {
    final RootFile file = getRootFileForDocId(documentId);
    InputStream is = RootCommands.getFile(file.getPath());

    try {
        return ParcelFileDescriptorUtil.pipeFrom(is);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return ParcelFileDescriptor.open(new File(file.getPath()), ParcelFileDescriptor.MODE_READ_ONLY);
}
 
开发者ID:kranthi0987,项目名称:easyfilemanager,代码行数:16,代码来源:RootedStorageProvider.java

示例13: openFile

import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
@Override
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
	File f = new File(getContext().getFilesDir(), CroperinoConfig.getsImageName());
	if (f.exists()) {
		return (ParcelFileDescriptor.open(f, ParcelFileDescriptor.MODE_READ_WRITE));
	}
	throw new FileNotFoundException(uri.getPath());
}
 
开发者ID:SalmanTKhan,项目名称:MyAnimeViewer,代码行数:9,代码来源:InternalStorageContentProvider.java

示例14: createDocument

import android.os.ParcelFileDescriptor; //导入方法依赖的package包/类
@Override
public PdfDocument createDocument(Context context, PdfiumCore core, String password) throws IOException {
    ParcelFileDescriptor pfd = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
    return core.newDocument(pfd, password);
}
 
开发者ID:barteksc,项目名称:AndroidPdfViewerV2,代码行数:6,代码来源:FileSource.java


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