This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
sample_code:backup_apps [2015/01/11 19:43] stevegarman created |
sample_code:backup_apps [2015/11/15 00:00] (current) |
||
---|---|---|---|
Line 4: | Line 4: | ||
The following code is intended as a guide to one way you can keep a snapshot of your code at any given time. | The following code is intended as a guide to one way you can keep a snapshot of your code at any given time. | ||
- | You may well find the archiving code more useful | + | If you wish, you can save the mail as a draft, rather |
+ | |||
+ | Or instead of choosing a mail app to send the file, you may be able to choose an archiving app that is on your device, such as **Google Drive**. | ||
<code JavaScript archive.js> | <code JavaScript archive.js> | ||
- | var mygmail = " | + | var mygmail = app.GetUser(); |
- | var mypass = " | + | var txt, |
// | // | ||
Line 14: | Line 16: | ||
{ | { | ||
// | // | ||
- | lay = app.CreateLayout( " | + | var lay = app.CreateLayout( " |
Line 24: | Line 26: | ||
app.AddLayout( lay ); | app.AddLayout( lay ); | ||
var fname = CreateArchive(); | var fname = CreateArchive(); | ||
- | sendGmail( mygmail, | + | yesNo = app.CreateYesNoDialog( " |
+ | yesNo.fname = fname; | ||
+ | yesNo.SetOnTouch( yesNoMail_OnTouch ); | ||
} | } | ||
// | // | ||
- | |||
function CreateArchive( ) | function CreateArchive( ) | ||
{ | { | ||
Line 36: | Line 39: | ||
var zip = app.CreateZipUtil(); | var zip = app.CreateZipUtil(); | ||
var fldr = "/ | var fldr = "/ | ||
- | var archname = (new Date).toISOString().slice(0, | + | archname = (new Date).toISOString().slice(0, |
- | archname = " | + | archname = " |
- | archname = archname.replace(/ | + | archname = archname.replace(/ |
- | var file = archfolder+archname+" | + | archname += " |
+ | var file = archfolder+archname; | ||
+ | archname = app.GetModel()+"/"+archname; | ||
zip.Create( file ); | zip.Create( file ); | ||
Line 52: | Line 57: | ||
// | // | ||
- | |||
function AddFolder( zip, | function AddFolder( zip, | ||
- | |||
{ | { | ||
txt.SetText(name); | txt.SetText(name); | ||
Line 67: | Line 70: | ||
} | } | ||
} | } | ||
- | + | //Handle ' | |
- | function sendGmail(addr, | + | function yesNoMail_OnTouch( result ) |
- | { | + | { |
- | //Create email object. | + | if( result=="Yes" |
- | var email = app.CreateEmail( addr, | + | { |
- | email.SetSMTP( "smtp.gmail.com", 465 ); | + | var fname = yesNo.fname; |
- | email.SetOnStatus( email_OnStatus ); | + | app.SendMail( mygmail, |
- | + | } | |
- | // | + | |
- | app.ShowProgress( "Sending..." | + | |
- | email.Send( attach, | + | |
- | addr, | + | |
} | } | ||
- | |||
- | // | ||
- | function email_OnStatus( status ) | ||
- | { | ||
- | app.HideProgress(); | ||
- | app.Alert( status ); | ||
- | } | ||
- | |||
</ | </ | ||
===== Warnings ===== | ===== Warnings ===== | ||
- | ==== Personalise the code ==== | ||
- | You must change the email address and password in the first two lines | ||
==== Version required ==== | ==== Version required ==== | ||
This code makes the assumption that you are using at least version 1.15 of DroidScript, | This code makes the assumption that you are using at least version 1.15 of DroidScript, | ||
- | ==== Possible Gmail Problem ==== | ||
- | The code used for emailing is pretty simplistic and you may get an authentication error if your gmail account is set to high security. | ||
==== Filling your sdcard ==== | ==== Filling your sdcard ==== | ||
There is no code included to delete the zip files. | There is no code included to delete the zip files. |