當前位置: 首頁>>代碼示例>>Java>>正文


Java ParcelFileDescriptor類代碼示例

本文整理匯總了Java中android.os.ParcelFileDescriptor的典型用法代碼示例。如果您正苦於以下問題:Java ParcelFileDescriptor類的具體用法?Java ParcelFileDescriptor怎麽用?Java ParcelFileDescriptor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ParcelFileDescriptor類屬於android.os包,在下文中一共展示了ParcelFileDescriptor類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: openFile

import android.os.ParcelFileDescriptor; //導入依賴的package包/類
@Override
public ParcelFileDescriptor openFile(Uri uri, String mode)
		throws FileNotFoundException {
       initIfNecessary();
	AssetFileDescriptor af = openAssetFile(uri, mode);
	if ( null != af ) {
		return af.getParcelFileDescriptor();
	}
	return null;
}
 
開發者ID:12d,項目名稱:react-native-videoplayer,代碼行數:11,代碼來源:APEZProvider.java

示例2: openDocument

import android.os.ParcelFileDescriptor; //導入依賴的package包/類
@Override
public ParcelFileDescriptor openDocument(String docId, String mode, CancellationSignal signal)
        throws FileNotFoundException {

    if (!"r".equals(mode)) {
        throw new IllegalArgumentException("Media is read-only");
    }

    final Uri target = getUriForDocumentId(docId);

    // Delegate to real provider
    final long token = Binder.clearCallingIdentity();
    try {
        return getContext().getContentResolver().openFileDescriptor(target, mode);
    } finally {
        Binder.restoreCallingIdentity(token);
    }
}
 
開發者ID:gigabytedevelopers,項目名稱:FireFiles,代碼行數:19,代碼來源:MediaDocumentsProvider.java

示例3: 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

示例4: writeToParcel

import android.os.ParcelFileDescriptor; //導入依賴的package包/類
@Override
public void writeToParcel(Parcel out, int flags) {
    if (mRelroFd >= 0) {
        out.writeLong(mLoadAddress);
        out.writeLong(mLoadSize);
        out.writeLong(mRelroStart);
        out.writeLong(mRelroSize);
        try {
            ParcelFileDescriptor fd = ParcelFileDescriptor.fromFd(mRelroFd);
            fd.writeToParcel(out, 0);
            fd.close();
        } catch (java.io.IOException e) {
            Log.e(TAG, "Can't write LibInfo file descriptor to parcel", e);
        }
    }
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:17,代碼來源:Linker.java

示例5: openReadInternal

import android.os.ParcelFileDescriptor; //導入依賴的package包/類
private ParcelFileDescriptor openReadInternal(String name) throws IOException {
    assertPreparedAndNotSealed("openRead");

    try {
        if (!FileUtils.isValidExtFilename(name)) {
            throw new IllegalArgumentException("Invalid name: " + name);
        }
        final File target = new File(resolveStageDir(), name);

        final FileDescriptor targetFd = Os.open(target.getAbsolutePath(), O_RDONLY, 0);
        return ParcelFileDescriptor.dup(targetFd);

    } catch (ErrnoException e) {
        throw new IOException(e);
    }
}
 
開發者ID:codehz,項目名稱:container,代碼行數:17,代碼來源:PackageInstallerSession.java

示例6: fileMd5Hash

import android.os.ParcelFileDescriptor; //導入依賴的package包/類
@Rpc(description = "Compute MD5 hash on a content URI. Return the MD5 has has a hex string.")
public String fileMd5Hash(String uri) throws IOException, NoSuchAlgorithmException {
    Uri uri_ = Uri.parse(uri);
    ParcelFileDescriptor pfd = mContext.getContentResolver().openFileDescriptor(uri_, "r");
    MessageDigest md = MessageDigest.getInstance("MD5");
    int length = (int) pfd.getStatSize();
    byte[] buf = new byte[length];
    ParcelFileDescriptor.AutoCloseInputStream stream =
            new ParcelFileDescriptor.AutoCloseInputStream(pfd);
    DigestInputStream dis = new DigestInputStream(stream, md);
    try {
        dis.read(buf, 0, length);
        return Utils.bytesToHexString(md.digest());
    } finally {
        dis.close();
        stream.close();
    }
}
 
開發者ID:google,項目名稱:mobly-bundled-snippets,代碼行數:19,代碼來源:FileSnippet.java

示例7: openVideoThumbnailCleared

import android.os.ParcelFileDescriptor; //導入依賴的package包/類
protected AssetFileDescriptor openVideoThumbnailCleared(long id, CancellationSignal signal)
        throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();
    Cursor cursor = null;
    try {
        cursor = resolver.query(Video.Thumbnails.EXTERNAL_CONTENT_URI,
                VideoThumbnailQuery.PROJECTION, Video.Thumbnails.VIDEO_ID + "=" + id, null,
                null);
        if (cursor.moveToFirst()) {
            final String data = cursor.getString(VideoThumbnailQuery._DATA);
            return new AssetFileDescriptor(ParcelFileDescriptor.open(
                    new File(data), ParcelFileDescriptor.MODE_READ_ONLY), 0,
                    AssetFileDescriptor.UNKNOWN_LENGTH);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
    }
    return null;
}
 
開發者ID:kranthi0987,項目名稱:easyfilemanager,代碼行數:20,代碼來源:StorageProvider.java

示例8: 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

示例9: modeToMode

import android.os.ParcelFileDescriptor; //導入依賴的package包/類
/**
 * Copied from ContentResolver.java
 */
private static int modeToMode(String mode) {
    int modeBits;
    if ("r".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_READ_ONLY;
    } else if ("w".equals(mode) || "wt".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_WRITE_ONLY
                | ParcelFileDescriptor.MODE_CREATE
                | ParcelFileDescriptor.MODE_TRUNCATE;
    } else if ("wa".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_WRITE_ONLY
                | ParcelFileDescriptor.MODE_CREATE
                | ParcelFileDescriptor.MODE_APPEND;
    } else if ("rw".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_READ_WRITE
                | ParcelFileDescriptor.MODE_CREATE;
    } else if ("rwt".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_READ_WRITE
                | ParcelFileDescriptor.MODE_CREATE
                | ParcelFileDescriptor.MODE_TRUNCATE;
    } else {
        throw new IllegalArgumentException("Invalid mode: " + mode);
    }
    return modeBits;
}
 
開發者ID:roshakorost,項目名稱:Phial,代碼行數:28,代碼來源:FileProvider.java

示例10: testLoadResource_returnsFileDescriptor

import android.os.ParcelFileDescriptor; //導入依賴的package包/類
@Test
public void testLoadResource_returnsFileDescriptor() throws Exception {
  Context context = RuntimeEnvironment.application;
  Uri uri = Uri.parse("file://nothing");

  ContentResolver contentResolver = context.getContentResolver();
  ContentResolverShadow shadow = Shadow.extract(contentResolver);

  AssetFileDescriptor assetFileDescriptor = mock(AssetFileDescriptor.class);
  ParcelFileDescriptor parcelFileDescriptor = mock(ParcelFileDescriptor.class);
  when(assetFileDescriptor.getParcelFileDescriptor()).thenReturn(parcelFileDescriptor);
  shadow.registerFileDescriptor(uri, assetFileDescriptor);

  FileDescriptorLocalUriFetcher fetcher =
      new FileDescriptorLocalUriFetcher(context.getContentResolver(), uri);
  fetcher.loadData(Priority.NORMAL, callback);
  verify(callback).onDataReady(eq(parcelFileDescriptor));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:FileDescriptorLocalUriFetcherTest.java

示例11: 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 = NativeAppCallAttachmentStore.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:eviltnan,項目名稱:kognitivo,代碼行數:21,代碼來源:FacebookContentProvider.java

示例12: initialize

import android.os.ParcelFileDescriptor; //導入依賴的package包/類
private void initialize()
        throws FileNotFoundException {
    ParcelFileDescriptor fileDescriptor = null;
    try {
        if (Utility.isFileUri(videoUri)) {
            fileDescriptor = ParcelFileDescriptor.open(
                    new File(videoUri.getPath()),
                    ParcelFileDescriptor.MODE_READ_ONLY);
            videoSize = fileDescriptor.getStatSize();
            videoStream = new ParcelFileDescriptor.AutoCloseInputStream(fileDescriptor);
        } else if (Utility.isContentUri(videoUri)) {
            videoSize = Utility.getContentSize(videoUri);
            videoStream = FacebookSdk
                    .getApplicationContext()
                    .getContentResolver()
                    .openInputStream(videoUri);
        } else {
            throw new FacebookException("Uri must be a content:// or file:// uri");
        }
    } catch (FileNotFoundException e) {
        Utility.closeQuietly(videoStream);

        throw e;
    }
}
 
開發者ID:eviltnan,項目名稱:kognitivo,代碼行數:26,代碼來源:VideoUploader.java

示例13: openFile

import android.os.ParcelFileDescriptor; //導入依賴的package包/類
@Override
public ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode) throws FileNotFoundException {
  final 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 {
      final PartUriParser partUri = new PartUriParser(uri);
      return getParcelStreamForAttachment(masterSecret, partUri.getPartId());
    } catch (IOException ioe) {
      Log.w(TAG, ioe);
      throw new FileNotFoundException("Error opening file");
    }
  }

  throw new FileNotFoundException("Request for bad part.");
}
 
開發者ID:CableIM,項目名稱:Cable-Android,代碼行數:25,代碼來源:PartProvider.java

示例14: parseMode

import android.os.ParcelFileDescriptor; //導入依賴的package包/類
public static int parseMode(String mode) {
    final int modeBits;
    if ("r".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_READ_ONLY;
    } else if ("w".equals(mode) || "wt".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_WRITE_ONLY
                | ParcelFileDescriptor.MODE_CREATE
                | ParcelFileDescriptor.MODE_TRUNCATE;
    } else if ("wa".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_WRITE_ONLY
                | ParcelFileDescriptor.MODE_CREATE
                | ParcelFileDescriptor.MODE_APPEND;
    } else if ("rw".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_READ_WRITE
                | ParcelFileDescriptor.MODE_CREATE;
    } else if ("rwt".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_READ_WRITE
                | ParcelFileDescriptor.MODE_CREATE
                | ParcelFileDescriptor.MODE_TRUNCATE;
    } else {
        throw new IllegalArgumentException("Bad mode '" + mode + "'");
    }
    return modeBits;
}
 
開發者ID:kranthi0987,項目名稱:easyfilemanager,代碼行數:25,代碼來源:Utils.java

示例15: openRenderer

import android.os.ParcelFileDescriptor; //導入依賴的package包/類
private void openRenderer( )  {
    // In this sample, we read a PDF from the assets directory.
    File f = new File(uri.getPath());
    try {
        mFileDescriptor = ParcelFileDescriptor.open(f, ParcelFileDescriptor.MODE_READ_ONLY);
        mPdfRenderer = new PdfRenderer(mFileDescriptor);
        cnt=mPdfRenderer.getPageCount();
    } catch (Exception e) {
        log.e(e);
    }
}
 
開發者ID:yippeesoft,項目名稱:NotifyTools,代碼行數:12,代碼來源:PdfActivity.java


注:本文中的android.os.ParcelFileDescriptor類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。