[Android] Save photos to "Bluesky" folder (#8018)

This commit is contained in:
Samuel Newman
2025-05-08 23:50:12 +03:00
committed by GitHub
parent 36697755c7
commit 207527f1d5
3 changed files with 32 additions and 4 deletions
+30 -2
View File
@@ -126,6 +126,8 @@ export async function shareImageModal({uri}: {uri: string}) {
safeDeleteAsync(imagePath)
}
const ALBUM_NAME = 'Bluesky'
export async function saveImageToMediaLibrary({uri}: {uri: string}) {
// download the file to cache
// NOTE
@@ -139,8 +141,34 @@ export async function saveImageToMediaLibrary({uri}: {uri: string}) {
imagePath = normalizePath(await moveToPermanentPath(imagePath, '.png'), true)
// save
await MediaLibrary.createAssetAsync(imagePath)
safeDeleteAsync(imagePath)
try {
if (isAndroid) {
// android triggers an annoying permission prompt if you try and move an image
// between albums. therefore, we need to either create the album with the image
// as the starting image, or put it directly into the album
const album = await MediaLibrary.getAlbumAsync(ALBUM_NAME)
if (album) {
// if album exists, put the image straight in there
await MediaLibrary.createAssetAsync(imagePath, album)
} else {
// otherwise, create album with asset (albums must always have at least one asset)
await MediaLibrary.createAlbumAsync(
ALBUM_NAME,
undefined,
undefined,
imagePath,
)
}
} else {
await MediaLibrary.createAssetAsync(imagePath)
}
} catch (err) {
logger.error(err instanceof Error ? err : String(err), {
message: 'Failed to save image to media library',
})
} finally {
safeDeleteAsync(imagePath)
}
}
export function getImageDim(path: string): Promise<Dimensions> {