User Tools

Site Tools


sample_code:backup_apps

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revision Both sides next revision
sample_code:backup_apps [2015/01/11 19:43]
stevegarman created
sample_code:backup_apps [2015/11/13 18:40]
stevegarman [Backup your apps]
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 than the email code.+If you wish, you can save the mail as a draft, rather than sending it.
  
 <code JavaScript archive.js> <code JavaScript archive.js>
-var mygmail = "mymail@gmail.com"; +//var mygmail = "my.own.address@gmail.com"; 
-var mypass "mypassword";+var mygmail app.GetUser();
  
 //Called when application is started. //Called when application is started.
Line 24: Line 24:
     app.AddLayout( lay );     app.AddLayout( lay );
     var fname = CreateArchive();     var fname = CreateArchive();
-    sendGmailmygmail, mypass, fname);+    yesNo = app.CreateYesNoDialog"Send by mail?" );  
 +    yesNo.fname = fname
 +    yesNo.SetOnTouch( yesNoMail_OnTouch );
 } }
  
 //Create a backup archive. //Create a backup archive.
- 
 function CreateArchive( ) function CreateArchive( )
 { {
Line 37: Line 38:
     var fldr = "/sdcard/DroidScript";     var fldr = "/sdcard/DroidScript";
     var archname = (new Date).toISOString().slice(0,19 );     var archname = (new Date).toISOString().slice(0,19 );
-    archname = "ds"+archname.replace(/[-:]/gi,""); +    archname = "ds"+archname.replace(/[-:]/g,""); 
-    archname =  archname.replace(/T/gi,"_");+    archname =  archname.replace(/T/,"_");
     var file = archfolder+archname+".zip";     var file = archfolder+archname+".zip";
     zip.Create( file );     zip.Create( file );
Line 52: Line 53:
  
 //Recursively add folder contents to zip. //Recursively add folder contents to zip.
- 
 function AddFolder( zip, name, fldr ) function AddFolder( zip, name, fldr )
- 
 { {
     txt.SetText(name);     txt.SetText(name);
Line 67: Line 66:
     }     }
 } }
- +//Handle 'send by mail?' dialog.  
-function sendGmail(addr,pass,attach) +function yesNoMail_OnTouchresult  
-+ 
-    //Create email object.  +    ifresult=="Yes" )  
-    var email = app.CreateEmailaddr, pass ) +    
-    email.SetSMTP( "smtp.gmail.com", 465 ) +        var fname = yesNo.fname
-    email.SetOnStatus( email_OnStatus )+        app.SendMailmygmail, fname, "DroidScript backup attached", fname ); 
- +    }
-    //Send the email message.  +
-    app.ShowProgress( "Sending..." );  +
-    email.Send( attach, "DroidScript backup for you.",   +
-       addr, addr, attach ); +
 } }
- 
-//Handle status messages.  
-function email_OnStatus( status )  
- 
-    app.HideProgress();  
-    app.Alert( status );  
- 
  
 </code> </code>
 ===== Warnings ===== ===== Warnings =====
 ==== Personalise the code ==== ==== Personalise the code ====
-You must change the email address and password in the first two lines+You must change the email address in the first line
 ==== Version required ==== ==== Version required ====
 This code makes the assumption that you are using at least version 1.15 of DroidScript, as the path for your apps is hard coded but older versions used a different path This code makes the assumption that you are using at least version 1.15 of DroidScript, as the path for your apps is hard coded but older versions used a different path
-==== 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.
sample_code/backup_apps.txt · Last modified: 2015/11/15 00:00 (external edit)