We want to connect the people who have knowledge to the people who need it, to bring together people with different perspectives so they can understand each other better, and to empower everyone to share their knowledge.
import android.content.ContentValues import android.content.Context import android.content.Intent import android.graphics.Bitmap import android.net.Uri import android.os.Build import android.os.Environment import android.provider.MediaStore import android.text.format.DateFormat import android.widget.Toast import java.io.File import java.io.FileOutputStream import java.io.OutputStream import java.util.* data class TakeSS(val bitmap: Bitmap, val context: Context, val img_name: String) { fun savescrolltoGallery() { val date = Date() val now = DateFormat.format("yyyyMMddhhmmss", date) val fos: OutputStream try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { val resolver = context.contentResolver val contentValue = ContentValues() contentValue.put(MediaStore.MediaColumns.DISPLAY_NAME, "$img_name.jpg") contentValue.put(MediaStore.MediaColumns.MIME_TYPE, "image/jpg") contentValue.put( MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_PICTURES + File.separator + "Huyền Học" ) val imageUri = resolver?.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValue) fos = resolver?.openOutputStream(Objects.requireNonNull(imageUri)!!)!! bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos) Toast.makeText(context, "$img_name.jpg", Toast.LENGTH_LONG).show() } else{ TakeSS(bitmap) } } catch (e: Exception) { Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show() } } fun TakeSS(contrain_content: Bitmap) { val date = Date() val now = DateFormat.format("yyyyMMddhhmmss", date) try { // image naming and path to include sd card appending name you choose for file val mPath = Environment.getExternalStorageDirectory() .toString() + "/Huyền Học/$img_name.jpg" val imageFile = File(mPath) imageFile.parentFile!!.mkdirs() val outputStream = FileOutputStream(imageFile) val quality = 100 contrain_content.compress( Bitmap.CompressFormat.JPEG, quality, outputStream ) outputStream.flush() outputStream.close() val uri = Uri.fromFile(imageFile) Toast.makeText(context, img_name, Toast.LENGTH_SHORT).show() } catch (e: Throwable) { // Several error may come out with file handling or DOM e.printStackTrace() } } }
val imageFile = File(mPath) imageFile.parentFile!!.mkdirs()
if (imageFile.parentFile != null && !imageFile.parentFile!!.exists()) { imageFile.parentFile!!.mkdirs() } if (!imageFile.exists()) { imageFile.createNewFile() }
catch (e: Throwable)
2.2K Point(s)
1.2K Point(s)
313 Point(s)
178 Point(s)
138 Point(s)
Input your email to receive reset password link, or if you remember your password, you can click