Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Somebody's terminal is dropping bits. I found a pile of them over in the corner.


computers / comp.mobile.android / How to save image to real sdcard?

SubjectAuthor
o How to save image to real sdcard?Jakub

1
How to save image to real sdcard?

<uafqt1$1t2$1$jakub@news.chmurka.net>

  copy mid

https://www.novabbs.com/computers/article-flat.php?id=43586&group=comp.mobile.android#43586

  copy link   Newsgroups: comp.mobile.android
Path: i2pn2.org!i2pn.org!news.chmurka.net!.POSTED.public-gprs400945.centertel.pl!not-for-mail
From: jak...@interia.pl (Jakub)
Newsgroups: comp.mobile.android
Subject: How to save image to real sdcard?
Date: Thu, 3 Aug 2023 11:12:25 +0200
Organization: news.chmurka.net
Message-ID: <uafqt1$1t2$1$jakub@news.chmurka.net>
NNTP-Posting-Host: public-gprs400945.centertel.pl
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 3 Aug 2023 09:09:53 -0000 (UTC)
Injection-Info: news.chmurka.net; posting-account="jakub"; posting-host="public-gprs400945.centertel.pl:37.47.197.114";
logging-data="1954"; mail-complaints-to="abuse-news.(at).chmurka.net"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Cancel-Lock: sha1:SoSo3nUrc2JlNiebVICEc83ROag= sha256:D5VaZelJOFgDiGNe0SaLPB9jH0B4Jxm7xkIghM1kL1I=
sha1:asOZIlTAlWnE2qKEydmrkSV8NCQ= sha256:I4Xy8JD7aQ6YaZ98xwpiXNPfkI/xF11JIkxqGlj+el8=
Content-Language: pl
 by: Jakub - Thu, 3 Aug 2023 09:12 UTC

Welcome

I have this function to save image external storege. But only save to
internal. How to fix this?

fun saveBitmapToExternal(context: Context,
bitmap: Bitmap,
fileName: String,
extension: String = "image/jpeg",
compressFormat: Bitmap.CompressFormat =
Bitmap.CompressFormat.JPEG,
qualityCompress: Int = 100) {

val date = System.currentTimeMillis()
var bitmapSave: Boolean

if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q ) {
val collection =
MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY)
val dirDest = Environment.DIRECTORY_DCIM + "/jphoto"
val directory = File(dirDest)
if ( !directory.exists() ) {
directory.mkdirs()
}

val newImage = ContentValues().apply {
put(MediaStore.Images.Media.DISPLAY_NAME, fileName)
put(MediaStore.MediaColumns.MIME_TYPE, extension)
put(MediaStore.MediaColumns.DATE_ADDED, date)
put(MediaStore.MediaColumns.DATE_MODIFIED, date)
put(MediaStore.MediaColumns.SIZE, bitmap.byteCount)
put(MediaStore.MediaColumns.WIDTH, bitmap.width)
put(MediaStore.MediaColumns.HEIGHT, bitmap.height)
put(MediaStore.MediaColumns.RELATIVE_PATH, dirDest)
put(MediaStore.Images.Media.IS_PENDING, 1)
}

val newImageUri =
context.contentResolver.insert(collection, newImage)

context.contentResolver.openOutputStream(newImageUri!!,
"w").use {
bitmapSave = bitmap.compress(compressFormat,
qualityCompress, it!!)
}

if ( bitmapSave ) {
showSnackBar(resources.getString(R.string.photo_done),
fontTextSize, Snackbar.LENGTH_SHORT, numberRow = 2)

newImage.clear()

newImage.put(MediaStore.Images.Media.IS_PENDING, 0)

context.contentResolver.update(newImageUri, newImage,
null, null)
} else {
context.contentResolver.delete(newImageUri, null, null)
showSnackBar(resources.getString(R.string.photo_add_error),
fontTextSize, Snackbar.LENGTH_SHORT, numberRow = 2)
}
} else {
val directory =
File(Environment.getExternalStorageDirectory().toString() + "/DCIM/jphoto")
if ( !directory.exists() ) {
directory.mkdirs()
}

val file = File(directory, fileName)
val save = saveImageToStream03(bitmap,
FileOutputStream(file), compressFormat, qualityCompress)

if ( save ) {
val values = ContentValues().apply {
put(MediaStore.Images.Media.DISPLAY_NAME, fileName)
put(MediaStore.MediaColumns.MIME_TYPE, extension)
put(MediaStore.MediaColumns.DATE_ADDED, date)
put(MediaStore.MediaColumns.DATE_MODIFIED, date)
put(MediaStore.MediaColumns.SIZE, bitmap.byteCount)
put(MediaStore.MediaColumns.WIDTH, bitmap.width)
put(MediaStore.MediaColumns.HEIGHT, bitmap.height)
put(MediaStore.Images.Media.DATA, file.absolutePath)
}
// .DATA is deprecated in API 29
context.contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
values)

showSnackBar(resources.getString(R.string.photo_done),
fontTextSize, Snackbar.LENGTH_SHORT, numberRow = 2)
} else {
if ( file.exists() ) {
file.delete()
}


showSnackBar(resources.getString(R.string.photo_add_error),
fontTextSize, Snackbar.LENGTH_SHORT, numberRow = 2)
}
}
}

private fun saveImageToStream03(
bitmap: Bitmap,
outputStream: OutputStream?,
compressFormat: Bitmap.CompressFormat = Bitmap.CompressFormat.JPEG,
qualityCompress: Int = 100
) : Boolean {
var bitmapSave = false

if ( outputStream != null ) {
try {
bitmapSave = bitmap.compress(compressFormat,
qualityCompress, outputStream)

outputStream.close()
} catch ( _ : Exception ) {
}
}

//outputStream.
return bitmapSave
}


computers / comp.mobile.android / How to save image to real sdcard?

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor