From the course: Android Development Essential Training: Manage Data with Kotlin

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Save files to external storage

Save files to external storage

From the course: Android Development Essential Training: Manage Data with Kotlin

Start my 1-month free trial

Save files to external storage

- [Narrator] Once you've set up the permission request for external files access, you're ready to do the actual work of writing to a file in external storage. Remember that it's always possible for a user to deny a permission after first granting it. Even after they've started up an app. So, any action you take that depends on a dangerous permission, should be wrapped in appropriate conditional logic. In my splash fragment class, I'm going to select and copy this bit of code that checks whether I have the external storage permission. And then, I'll go to my repository class. And down here, in my save data to cache function, I'll paste that logic into place and accept the imports. Then, I'll add the closing brace right here and reformat my code. In this class, I'm not in a fragment so I don't have access to the required context function. But, I still need to pass in a context, so I'll pass in the application reference that's declared as part of this class's constructor. So now, I'll…

Contents