1

I have been trying to make an android app (via kivy launcher) that automatically makes a backup each time you save to a .db file.

When running kivy on my pc, the program works perfectly, but when I use it on my phone via kivy launcher, the program just crashes. Interestingly, the next time I go into the kivy launcher, the backup file appears in the directory it was supposed to be saved in.

I copy the .db file using shutil:

shutil.copy('test.db','BACKUP_'+self.time+'.db')

here is the python code

here is the kivy log file

The last few errors suggest there is some problem with the shutil.copy() method I am using to copy the files, but I really don't understand why it is giving me the error. I think it might have to do with android having issue with the directory I want to save the backup to, or maybe some permission issues.

I am using shutil because it comes with the default python 3 library as far as I understand. I am also using the android kivy launcher because I haven't yet learned how to export a .apk file (I heard you need to use buildozer on linux or mac and I run windows).

I would appreciate it if anyone could give me advice on how I can copy the .db file as a backup on android using kivy launcher.

ShaunBach
  • 31
  • 1
  • 4
  • I'm not sure what's wrong here, shutil should work as far as I know. Are you able to create and write to files in other ways, without getting errors like this? – inclement Jun 11 '18 at 19:43
  • I can read from a text file without issues(on andoid and pc). I can also read and write to a .db file in sqlite3 (on android and pc). As I mentioned above, copying files with shutil works on my pc, but on android it crashes (but then still makes the copy when I go back into kivy launcher) so it is rather confusing. – ShaunBach Jun 12 '18 at 19:52

1 Answers1

0

You can't use shutil.copy on android. Because "Error Operation not permitted"(Test on Galaxy A8 2018)

I had a similar problem today with android kivy buildozer, I haven't had time to solve it, but I think this solution can be used:

with open("filename", "rb") as f:
    data = f.read()
with open("new filename", "wb") as f:
    f.write(data)

This is a image


Update, Shutil.copy has copied successfully, but he still throws an error: "[Errno 1] Operation not permitted:", maybe you can use try,except to ignore it.

Other things you need to do is "Rescan the android mediastore" if the file is a media and you will want to see it at media browser. "Refresh MediaStore on Android Kivy Example"

General Grievance
  • 4,555
  • 31
  • 31
  • 45
謝咏辰
  • 37
  • 4