当前位置: 首页>>代码示例>>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;未经允许,请勿转载。