Search code examples
pythonandroidkivyandroid-permissionsmobile-application

What is the Android permission needed to save files?


I created an app called Paint Maker Pro with Kivy and Python code and now it's on the Google Play Store. People have told me the Save as JPEG feature doesn't work. And that's true. I want the user to be able to save their work so they can share it with other people. And when a user clicks the Save as JPEG button, the drawing gets saved in the current working directory on Linux and Windows. On Android though, the app says the drawing was saved but it never gets saved. Here's the code I used:

# IMPORTS AND A LOT OF OTHER CODE
def save_canvas(self, for_kivy):
    filename = datetime.now().strftime('PMP_Drawing_at_%a_%b_%d_%I:%M:%S:%f_%p_%Y.jpg')
    self.root.export_as_image().save(filename)
    self.btn_col = (uniform(0, 1), uniform(0, 1), uniform(0, 1), 1)
    self.save_btn_jpg.background_color = self.btn_col
    self.clear_btn.background_color = self.btn_col
    self.select_col_btn.background_color = self.btn_col
    self.erase_btn.background_color = self.btn_col
    self.pt_10.background_color = self.btn_col
    self.pt_20.background_color = self.btn_col
    self.pt_30.background_color = self.btn_col
    self.pt_40.background_color = self.btn_col
    self.pt_50.background_color = self.btn_col
    self.pt_60.background_color = self.btn_col
    self.rec_btn.background_color = self.btn_col
    self.cir_btn.background_color = self.btn_col
    popup.pop(filename, Label(text='Drawing saved at:\n' +
                              getcwd() + '.', font_size=self.font_15))

I'm pretty sure this is because of some Android permission error. So does anyone know what permission I'm supposed to use? I've already tried WRITE_EXTERNAL_STORAGE.


Solution

  • I've fixed my app, but if anyone didn't know how to use special permissions, here's how:

    from kivy.utils import platform
    from android.permissions import request_permissions, Permission
    # Android module doesn't have to be installed because it will automatically get
    # included in the APK
    # ------ OTHER IMPORTS ------
    
    # ------ APP CODE ------
    
    if __name__ in ['__android__', '__main__']:
     if platform == 'android':
      request_permissions([Permission.WRITE_EXTERNAL_STORAGE, ...]) # All permissions your app requires
     # ------ RUN APP ------