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


Java ParcelFileDescriptor.getFileDescriptor方法代碼示例

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


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

示例1: cutFile

import android.os.ParcelFileDescriptor; //導入方法依賴的package包/類
public static void cutFile(File sourceFile, File destFile) throws IOException {

        FileChannel destination = null;
        FileChannel source = null;
        ParcelFileDescriptor pfd = null;
        try {
            source = new FileInputStream(sourceFile).getChannel();

            if (MusicUtils.isFromSdCard(destFile.getAbsolutePath())) {
                DocumentFile documentFile = FileUtils.getDocumentFile(destFile);
                pfd = Common.getInstance().getContentResolver().openFileDescriptor(documentFile.getUri(), "w");
                FileOutputStream outputStream = new FileOutputStream(pfd.getFileDescriptor());
                destination = outputStream.getChannel();
            } else {
                destination = new FileOutputStream(destFile).getChannel();
            }


            if (!destFile.getParentFile().exists())
                destFile.getParentFile().mkdirs();

            if (!destFile.exists()) {
                destFile.createNewFile();
            }


            destination.transferFrom(source, 0, source.size());

        } catch (Exception e) {
            e.printStackTrace();
            Logger.log("MESSAGE -" + e.getMessage() + "CAUSE " + e.getCause());
        } finally {
            deleteRecursive(sourceFile);
            if (pfd != null) {
                pfd.close();
            }
            if (source != null) {
                source.close();
            }
            if (destination != null) {
                destination.close();
            }
        }
    }
 
開發者ID:reyanshmishra,項目名稱:Rey-MusicPlayer,代碼行數:45,代碼來源:FileUtils.java

示例2: getEligiblePackages

import android.os.ParcelFileDescriptor; //導入方法依賴的package包/類
private List<String> getEligiblePackages(Uri contentUri, Activity context) throws IOException {
    List<String> results = new LinkedList<>();

    ParcelFileDescriptor fileDescriptor = context.getContentResolver().openFileDescriptor(contentUri, "r");
    FileInputStream fileInputStream = new FileInputStream(fileDescriptor.getFileDescriptor());
    ZipInputStream inputStream = new ZipInputStream(fileInputStream);

    ZipEntry zipEntry;
    while ((zipEntry = inputStream.getNextEntry()) != null) {
        String zipEntryPath = zipEntry.getName();

        if (zipEntryPath.startsWith(ContentProviderBackupConfigurationBuilder.DEFAULT_FULL_BACKUP_DIRECTORY)) {
            String fileName = new File(zipEntryPath).getName();
            results.add(fileName);
        }

        inputStream.closeEntry();
    }

    IoUtils.closeQuietly(inputStream);
    IoUtils.closeQuietly(fileDescriptor.getFileDescriptor());
    return results;
}
 
開發者ID:stevesoltys,項目名稱:backup,代碼行數:24,代碼來源:RestoreBackupActivityController.java

示例3: getBitpMap

import android.os.ParcelFileDescriptor; //導入方法依賴的package包/類
public static Bitmap getBitpMap(Context context, Uri uri, Display display) {
	ParcelFileDescriptor pfd;
	try {
		pfd = context.getContentResolver().openFileDescriptor(uri, "r");
	} catch (IOException ex) {
		return null;
	}
	java.io.FileDescriptor fd = pfd.getFileDescriptor();
	BitmapFactory.Options options = new BitmapFactory.Options();
	// 先指定原始大小
	options.inSampleSize = 1;
	// 隻進行大小判斷
	options.inJustDecodeBounds = true;
	// 調用此方法得到options得到圖片的大小
	BitmapFactory.decodeFileDescriptor(fd, null, options);
	// 我們的目標是在800pixel的畫麵上顯示。
	// 所以需要調用computeSampleSize得到圖片縮放的比例
	options.inSampleSize = computeSampleSize(options, display.getWidth(),
			display.getHeight());
	// OK,我們得到了縮放的比例,現在開始正式讀入BitMap數據
	options.inJustDecodeBounds = false;
	options.inDither = false;
	options.inPreferredConfig = Bitmap.Config.ARGB_8888;

	// 根據options參數,減少所需要的內存
	Bitmap sourceBitmap = BitmapFactory.decodeFileDescriptor(fd, null,
			options);
	return sourceBitmap;
}
 
開發者ID:PlutoArchitecture,項目名稱:Pluto-Android,代碼行數:30,代碼來源:PhotoUtil.java

示例4: decodeSampledBitmapFromUri

import android.os.ParcelFileDescriptor; //導入方法依賴的package包/類
private Bitmap decodeSampledBitmapFromUri(Uri imageUri, int reqWidth, int reqHeight) {

        Bitmap bitmap;
        ParcelFileDescriptor parcelFileDescriptor =  null;

        try {
            parcelFileDescriptor = mContext.getContentResolver().openFileDescriptor(imageUri, "r");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        if (parcelFileDescriptor != null) {
            FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();

            // decode with inJustDecodeBounds=true to check dimensions
            final BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);

            // calculate inSampleSize
            options.inSampleSize = calculateSampleParameter(options, reqWidth, reqHeight);

            // decode bitmap with inSampleSize set
            options.inJustDecodeBounds = false;
            bitmap = BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);

            return bitmap;

        } else {
            return null;
        }

    }
 
開發者ID:malah-code,項目名稱:Open-Quran-Radio,代碼行數:34,代碼來源:ImageHelper.java

示例5: writeNewStateDescription

import android.os.ParcelFileDescriptor; //導入方法依賴的package包/類
@Override
public void writeNewStateDescription(ParcelFileDescriptor newState) {
    long fileModified = databaseFile.lastModified();
    try {
        FileOutputStream outstream = new FileOutputStream(newState.getFileDescriptor());
        DataOutputStream out = new DataOutputStream(outstream);
        out.writeLong(fileModified);
        out.close();
    } catch (IOException e) {
        Log.e(THIS_FILE, "Cannot manage final local backup state", e);
    }
}
 
開發者ID:treasure-lau,項目名稱:CSipSimple,代碼行數:13,代碼來源:SipProfilesHelper.java

示例6: writeUri

import android.os.ParcelFileDescriptor; //導入方法依賴的package包/類
private void writeUri(Uri uri, String newContent, String encoding) throws IOException {
    ParcelFileDescriptor pfd = activity.getContentResolver().openFileDescriptor(uri, "w");
    FileOutputStream fileOutputStream = new FileOutputStream(pfd.getFileDescriptor());
    fileOutputStream.write(newContent.getBytes(Charset.forName(encoding)));
    fileOutputStream.close();
    pfd.close();
}
 
開發者ID:ujjwalagrawal17,項目名稱:CodeCompilerApp,代碼行數:8,代碼來源:SaveFileTask.java

示例7: handleVideo

import android.os.ParcelFileDescriptor; //導入方法依賴的package包/類
private void handleVideo(MediaInfo mVideoInfo) {
        mCurrentVideoInfo = mVideoInfo;
        String assetpath = mVideoInfo.getAssetcover();
        File srcFile = new File(assetpath);
        int dotindex = assetpath.lastIndexOf(".");
        if (dotindex != -1) {
            String type = assetpath.substring(dotindex, assetpath.length());
            String compressPath = mSession.getCompressPath();
            if (Build.VERSION.SDK_INT >= 18) {
                FileOutputStream fos = null;
                try {
                    mCacheVideoPath = compressPath + (compressPath.endsWith(File.separator) ? "" : File.separator) + "savorVideo" + type;
                    Uri uriForFile = FileProvider.getUriForFile(this, "com.savor.savorphone.fileprovider", srcFile);
                    ContentResolver contentResolver = getContentResolver();
                    ParcelFileDescriptor pFileDesCripter = contentResolver.openFileDescriptor(uriForFile, "r");
                    FileDescriptor fileDesCripter = pFileDesCripter.getFileDescriptor();
//                    MediaTranscoder.getInstance().transcodeVideo(fileDesCripter, mCacheVideoPath,
//                            MediaFormatStrategyPresets.createExportPreset960x540Strategy(), listener);
                    future = MediaTranscoder.getInstance().transcodeVideo(fileDesCripter, mCacheVideoPath,
                            MediaFormatStrategyPresets.createAndroid720pStrategy(8000 * 1000, 128 * 1000, 1), listener);
                } catch (Exception e) {
                    e.printStackTrace();
                    handleFileCopy(mVideoInfo, srcFile, type, compressPath);
                }
            } else {
                handleFileCopy(mVideoInfo, srcFile, type, compressPath);
            }
        }
    }
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:30,代碼來源:MediaGalleryActivity.java

示例8: BackupState

import android.os.ParcelFileDescriptor; //導入方法依賴的package包/類
@SuppressFBWarnings(value = {"OS_OPEN_STREAM"}, justification = "Closed by backup system")
@SuppressWarnings("unchecked")
public BackupState(ParcelFileDescriptor parceledState) throws IOException {
    if (parceledState == null) return;
    try {
        FileInputStream instream = new FileInputStream(parceledState.getFileDescriptor());
        ObjectInputStream in = new ObjectInputStream(instream);
        mNames = (ArrayList<String>) in.readObject();
        mValues = (ArrayList<byte[]>) in.readObject();
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:14,代碼來源:ChromeBackupAgent.java

示例9: save

import android.os.ParcelFileDescriptor; //導入方法依賴的package包/類
@SuppressFBWarnings(value = {"OS_OPEN_STREAM"}, justification = "Closed by backup system")
public void save(ParcelFileDescriptor parceledState) throws IOException {
    FileOutputStream outstream = new FileOutputStream(parceledState.getFileDescriptor());
    ObjectOutputStream out = new ObjectOutputStream(outstream);
    out.writeObject(mNames);
    out.writeObject(mValues);
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:8,代碼來源:ChromeBackupAgent.java

示例10: initializeOutputStream

import android.os.ParcelFileDescriptor; //導入方法依賴的package包/類
private void initializeOutputStream() throws FileNotFoundException {
    ContentResolver contentResolver = configuration.getContext().getContentResolver();
    ParcelFileDescriptor outputFileDescriptor = contentResolver.openFileDescriptor(configuration.getUri(), "w");
    backupState.setOutputFileDescriptor(outputFileDescriptor);

    FileOutputStream fileOutputStream = new FileOutputStream(outputFileDescriptor.getFileDescriptor());
    ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream);
    backupState.setOutputStream(zipOutputStream);
}
 
開發者ID:stevesoltys,項目名稱:backup,代碼行數:10,代碼來源:ContentProviderBackupComponent.java

示例11: performExport

import android.os.ParcelFileDescriptor; //導入方法依賴的package包/類
@SuppressWarnings("ConstantConditions")
public static void performExport(final Context context, final Uri uri) throws IOException {
    final String title = context.getString(R.string.opml_export_title);
    final ParcelFileDescriptor pfd =
            context.getContentResolver().openFileDescriptor(uri, "w");

    final FileDescriptor fd = pfd.getFileDescriptor();
    final FileOutputStream fos = new FileOutputStream(fd);

    final OPMLFile OPMLFile = new OPMLFile();

    final OPMLFile.Head head = OPMLFile.getHead();
    final OPMLFile.Body body = OPMLFile.getBody();

    head.setElementOfHead(ATTRIBUTE_DATE_CREATED, new Date());
    head.setElementOfHead(ATTRIBUTE_TITLE, title);

    final LinkedListMultimap<String, String> feedMetaData =
            SharedPrefUtils.getFeedMetaData(context);

    for (final String name : feedMetaData.asMap().keySet()) {
        final String xmlUrl = feedMetaData.get(name).get(FEED_URL);

        final LinkedHashMap<String, Object> attrs = new LinkedHashMap<>(4);

        attrs.put(ATTRIBUTE_TEXT, name);
        attrs.put(ATTRIBUTE_TITLE, name);
        attrs.put(ATTRIBUTE_TYPE, "rss");
        attrs.put(ATTRIBUTE_XML_URL, xmlUrl);

        body.addOutline(new Outline(attrs));
    }

    fos.write(OPMLFile.toString().getBytes(StandardCharsets.UTF_8));

    fos.close();
    pfd.close();
}
 
開發者ID:Applications-Development,項目名稱:SimpleRssReader,代碼行數:39,代碼來源:OPMLUtils.java

示例12: transferIncrementalRestoreData

import android.os.ParcelFileDescriptor; //導入方法依賴的package包/類
private int transferIncrementalRestoreData(String packageName, ParcelFileDescriptor outputFileDescriptor)
        throws IOException, InvalidAlgorithmParameterException, InvalidKeyException {

    ParcelFileDescriptor inputFileDescriptor = buildInputFileDescriptor();
    ZipInputStream inputStream = buildInputStream(inputFileDescriptor);
    BackupDataOutput backupDataOutput = new BackupDataOutput(outputFileDescriptor.getFileDescriptor());

    Optional<ZipEntry> zipEntryOptional = seekToEntry(inputStream,
            configuration.getIncrementalBackupDirectory() + packageName);
    while (zipEntryOptional.isPresent()) {
        String fileName = new File(zipEntryOptional.get().getName()).getName();
        String blobKey = new String(Base64.decode(fileName, Base64.DEFAULT));

        byte[] backupData = Streams.readFullyNoClose(inputStream);
        backupDataOutput.writeEntityHeader(blobKey, backupData.length);
        backupDataOutput.writeEntityData(backupData, backupData.length);
        inputStream.closeEntry();

        zipEntryOptional = seekToEntry(inputStream, configuration.getIncrementalBackupDirectory() + packageName);
    }

    IoUtils.closeQuietly(inputFileDescriptor);
    IoUtils.closeQuietly(outputFileDescriptor);
    return TRANSPORT_OK;
}
 
開發者ID:stevesoltys,項目名稱:backup,代碼行數:26,代碼來源:ContentProviderRestoreComponent.java

示例13: writeStateFile

import android.os.ParcelFileDescriptor; //導入方法依賴的package包/類
/**
 * Write out the new state file:  the version number, followed by the
 * three bits of data as we sent them off to the backup transport.
 */
void writeStateFile(ParcelFileDescriptor stateFile) throws IOException {
    FileOutputStream outstream = new FileOutputStream(stateFile.getFileDescriptor());
    DataOutputStream out = new DataOutputStream(outstream);

    out.writeInt(mFilling);
    out.writeBoolean(mAddMayo);
    out.writeBoolean(mAddTomato);
}
 
開發者ID:sdrausty,項目名稱:buildAPKsSamples,代碼行數:13,代碼來源:MultiRecordExampleAgent.java

示例14: compareStateFile

import android.os.ParcelFileDescriptor; //導入方法依賴的package包/類
/**
 * Helper routine - read a previous state file and decide whether to
 * perform a backup based on its contents.
 *
 * @return <code>true</code> if the application's data has changed since
 *   the last backup operation; <code>false</code> otherwise.
 */
boolean compareStateFile(ParcelFileDescriptor oldState) {
    FileInputStream instream = new FileInputStream(oldState.getFileDescriptor());
    DataInputStream in = new DataInputStream(instream);

    try {
        int stateVersion = in.readInt();
        if (stateVersion > AGENT_VERSION) {
            // Whoops; the last version of the app that backed up
            // data on this device was <em>newer</em> than the current
            // version -- the user has downgraded.  That's problematic.
            // In this implementation, we recover by simply rewriting
            // the backup.
            return true;
        }

        // The state data we store is just a mirror of the app's data;
        // read it from the state file then return 'true' if any of
        // it differs from the current data.
        int lastFilling = in.readInt();
        boolean lastMayo = in.readBoolean();
        boolean lastTomato = in.readBoolean();

        return (lastFilling != mFilling)
                || (lastTomato != mAddTomato)
                || (lastMayo != mAddMayo);
    } catch (IOException e) {
        // If something went wrong reading the state file, be safe
        // and back up the data again.
        return true;
    }
}
 
開發者ID:sdrausty,項目名稱:buildAPKsSamples,代碼行數:39,代碼來源:ExampleAgent.java

示例15: writeStateFile

import android.os.ParcelFileDescriptor; //導入方法依賴的package包/類
/**
 * Write out the new state file:  the version number, followed by the
 * three bits of data as we sent them off to the backup transport.
 */
void writeStateFile(ParcelFileDescriptor stateFile) throws IOException {
    FileOutputStream outstream = new FileOutputStream(stateFile.getFileDescriptor());
    DataOutputStream out = new DataOutputStream(outstream);

    out.writeInt(AGENT_VERSION);
    out.writeInt(mFilling);
    out.writeBoolean(mAddMayo);
    out.writeBoolean(mAddTomato);
}
 
開發者ID:sdrausty,項目名稱:buildAPKsSamples,代碼行數:14,代碼來源:ExampleAgent.java


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