本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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;
}
}