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


Java ContentResolver.openOutputStream方法代码示例

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


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

示例1: getOutputStream

import android.content.ContentResolver; //导入方法依赖的package包/类
public static OutputStream getOutputStream(final Context c, final Uri u)
{
    try
    {
        ContentResolver cr = c.getContentResolver();
        OutputStream os = cr.openOutputStream(u);
        ViewUtils.Debug(c, "writing uri: " + u.toString());
        if (os != null)
        {
            return os;
        }
    }
    catch (Exception e)
    {
        final String error = String.format(c.getResources().getString(R.string.error_file_write),
                u.getLastPathSegment());
        ViewUtils.Debug(c, error + ", " + e.getLocalizedMessage());
        Toast.makeText(c, error, Toast.LENGTH_LONG).show();
    }
    return null;
}
 
开发者ID:mkulesh,项目名称:microMathematics,代码行数:22,代码来源:FileUtils.java

示例2: copyFileOntoRemovableStorage

import android.content.ContentResolver; //导入方法依赖的package包/类
static boolean copyFileOntoRemovableStorage(Context context, Uri treeUri,
                                            String path, String destination) throws IOException {
    String mimeType = MediaType.getMimeType(path);
    DocumentFile file = DocumentFile.fromFile(new File(destination));
    if (file.exists()) {
        int index = destination.lastIndexOf(".");
        destination = destination.substring(0, index) + " Copy"
                + destination.substring(index, destination.length());
    }
    DocumentFile destinationFile = StorageUtil.createDocumentFile(context, treeUri, destination, mimeType);

    if (destinationFile != null) {
        ContentResolver resolver = context.getContentResolver();
        OutputStream outputStream = resolver.openOutputStream(destinationFile.getUri());
        InputStream inputStream = new FileInputStream(path);
        return writeStream(inputStream, outputStream);
    }
    return false;
}
 
开发者ID:kollerlukas,项目名称:Camera-Roll-Android-App,代码行数:20,代码来源:Copy.java

示例3: saveImageToExternal

import android.content.ContentResolver; //导入方法依赖的package包/类
public static void saveImageToExternal(Context context, String imgName, Bitmap bm) throws IOException {

        ContentResolver cr = context.getContentResolver();

        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, imgName + ".png");
        values.put(MediaStore.Images.Media.DESCRIPTION, imgName);
        values.put(MediaStore.Images.Media.MIME_TYPE, "image/png");

        Uri url = cr.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);

        OutputStream imageOut = cr.openOutputStream(url);
        try {
            bm.compress(Bitmap.CompressFormat.PNG, 100, imageOut); // Compress Image
        } catch (Exception ex) {
            throw ex;
        } finally {
            imageOut.close();
        }

        long id = ContentUris.parseId(url);

        // Wait until MINI_KIND thumbnail is generated.
        Bitmap miniThumb = MediaStore.Images.Thumbnails.getThumbnail(cr, id,
                MediaStore.Images.Thumbnails.MINI_KIND, null);

    }
 
开发者ID:csarron,项目名称:renderscript_examples,代码行数:28,代码来源:Util.java

示例4: saveThumbnail

import android.content.ContentResolver; //导入方法依赖的package包/类
private static boolean saveThumbnail(ContentResolver cr, File thumbFile, Bitmap thumb) {
       if (thumb == null) return false;
       try {
           Uri uri = Uri.fromFile(thumbFile);
           OutputStream thumbOut = cr.openOutputStream(uri);
           thumb.compress(Bitmap.CompressFormat.JPEG, 85, thumbOut);
           thumbOut.close();
           return true;
       } catch (Throwable t) {
           Log.e(TAG, "Unable to store thumbnail", t);
           return false;
       }
}
 
开发者ID:tiberiusteng,项目名称:financisto1-holo,代码行数:14,代码来源:ThumbnailUtil.java


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