/** * 将拍的照片添加到相册 * * @param uri 拍的照片的Uri */ privatefungalleryAddPic(uri: Uri?) { val mediaScanIntent = Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,uri) sendBroadcast(mediaScanIntent) }
But it has a question
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
funcreateImageFile(context: Context): File? { // Create an image file name val timeStamp: String = SimpleDateFormat(yyyyMMDD_HHmmss).format(Date()) // val storageDir: File? = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES) val storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
return File.createTempFile( "JPEG_${timeStamp}_", /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ).apply { // Save a file: path for use with ACTION_VIEW intents var currentPhotoPath = absolutePath Timber.i("createImageFile $currentPhotoPath") } }