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
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 than the email code.+If you wish, you can save the mail as a draft, rather than sending it. 
 + 
 +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 = "mymail@gmail.com"+var mygmail = app.GetUser()
-var mypass = "mypassword";+var txt, yesNo, archname;
  
 //Called when application is started. //Called when application is started.
Line 14: Line 16:
 { {
     //Create a layout with objects vertically centered.     //Create a layout with objects vertically centered.
-    lay = app.CreateLayout( "linear", "FillXY" );    +    var lay = app.CreateLayout( "linear", "FillXY" );    
  
  
Line 24: Line 26:
     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 36: Line 39:
     var zip = app.CreateZipUtil();     var zip = app.CreateZipUtil();
     var fldr = "/sdcard/DroidScript";     var fldr = "/sdcard/DroidScript";
-    var archname = (new Date).toISOString().slice(0,19 ); +    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";+    archname += ".zip"
 +    var file = archfolder+archname
 +    archname = app.GetModel()+"/"+archname;
     zip.Create( file );     zip.Create( file );
  
Line 52: Line 57:
  
 //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 70:
     }     }
 } }
- +//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, archname, "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 ==== 
-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, 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.1421005391.txt.gz · Last modified: 2015/01/12 03:43 (external edit)