apps-android-wikipedia
apps-android-wikipedia copied to clipboard
Export reading list into a csv file
Phab: https://phabricator.wikimedia.org/T316839
A couple of (unsolicited) notes and hints:
- Requesting permissions is only necessary for API <29. For API 29+, scoped storage will work automatically.
- Opening a file in the Downloads directory automatically can be done with
getExternalStoragePublicDirectory(...)for <29, and for 29+ usingcontentResolver.insert(...). - When showing a notification after the file is written, the intent of the notification can go directly to the Downloads directory:
intent = Intent(DownloadManager.ACTION_VIEW_DOWNLOADS)
@sharvaniharan Here's some rough code for creating a file in the Downloads folder using scoped storage (for API 29+):
val fileName = "foo.csv"
val contentResolver = context.contentResolver
val contentValues = ContentValues()
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, fileName) // The file name is just the name, not the full path!
contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "text/csv")
val uri = contentResolver.insert(MediaStore.Downloads.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY), contentValues)
val outputStream = contentResolver.openOutputStream(uri!!)!!
@sharvaniharan One of the requirements in the phab task is to export multiple lists, which means implementing "multi-select" logic in the reading lists screen. Will that be part of this PR, or a follow-on PR?
@dbrant will be doing that in a separate PR.