當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。