Backup Your Apps

1,174 views
Skip to first unread message

Steve Garman

unread,
Jan 11, 2015, 3:01:28 PM1/11/15
to androi...@googlegroups.com
Following Dave's reminder that we should be backing up our apps, I thought I would post some sample code on the wiki that might help.

It is at http://wiki.droidscript.me.uk/doku.php?id=sample_code:backup_apps though you will probably not want to use it exactly as the sample is written.

Steve Garman

unread,
Jan 11, 2015, 6:50:58 PM1/11/15
to androi...@googlegroups.com
I have amended the sample to use an external mail app.

This avoids a potential security problem with gmail.

salvatore fusto

unread,
Jan 16, 2015, 4:57:06 AM1/16/15
to androi...@googlegroups.com
Hi all,
sure you can have a lot of backup strategies; i use a simple app:
//Called when application is started.
function OnStart()
{
//Create a layout with objects vertically centered.
lay = app.CreateLayout( "linear", "VCenter,FillXY" );
btn=app.CreateButton("Copy",-1,0.1)
btn.SetOnTouch(copy)
lay.AddChild(btn)
app.AddLayout( lay );
}

function copy(){
var source= "../";
var destination="/Removable/MicroSD/backups";
    app.ExtractAssets(source,destination,true)
    app.ShowPopup("Done")
that moves all projects to an external microsd on my device.
regards
salvatore

Steve Garman

unread,
Jan 16, 2015, 1:11:19 PM1/16/15
to androi...@googlegroups.com
That's certainly a perfectly respectable form of backup, Salvatore.

The reason I backup to zip is that it enables me to keep lots of different versions of my code.

That way, when I make one of my usual massive blunders and don't realise for a while, I am able to track down a pre-blunder version.

Gabriele Cozzolino

unread,
Nov 13, 2015, 1:13:11 PM11/13/15
to DroidScript
Hi Steve, thank you for this code, I have a little problem on my nexus 5 with Android 6.0, when I choose to send the email it opens gmail that return the error "Cannot attach an empty file", but if I go to check the zip file I can see it is not empty.

Steve Garman

unread,
Nov 13, 2015, 1:25:45 PM11/13/15
to DroidScript
Sorry Gabriele, I haven't got Marshmallow here to test.

It works OK for me on Lollipop.

Has anyone else tried it on 6.0?

aa bb

unread,
Nov 14, 2015, 4:02:24 AM11/14/15
to DroidScript
Share via email works for me on android 6 (tried with aosp email app)

Gabriele Cozzolino

unread,
Nov 14, 2015, 4:08:33 AM11/14/15
to DroidScript
Doesn't work with gmail but it works with google drive, even better :-)

aa bb

unread,
Nov 14, 2015, 5:41:31 AM11/14/15
to DroidScript
For gmail you could check the permissions for the app, maybe some needed is not activated

Andy Barnhart

unread,
Feb 10, 2016, 9:11:03 PM2/10/16
to DroidScript
Thanks for that. I just started messing around with DroidScript and that made a nice first project to combine that with the Intents sample to send the zip file to Drive. I could get lazy and go select the DS folder in the Verizon cloud back up and if I start doing much I probably will so I don't have to remember. But as someone else mentioned, this would be the sort of thing to do at specific levels of functionality or if you release it and aren't using any SCM.

Andy Barnhart

unread,
Feb 21, 2016, 8:55:14 AM2/21/16
to DroidScript
A couple of other little touches others may like (or not). Creates .archive folder under DroidScript, ignores .edit and .archive folder and offers the Drive copy.
var mygmail = app.GetUser();
var txt, yesNo, archname;
 
//Called when application is started.
function OnStart()
{
    //Create a layout with objects vertically centered.
    var lay = app.CreateLayout( "linear", "FillXY" );    
 
 
    //Create a text label and add it to layout.
    txt = app.CreateText( "..." );
    lay.AddChild( txt );
 
    //Add layout to app.    
    app.AddLayout( lay );
    var fname = CreateArchive();
    yesNo = app.CreateYesNoDialog( "Save to Drive?" ); 
    yesNo.fname = fname;
    yesNo.SetOnTouch( yesNoDrive_OnTouch );
}
 
//Create a backup archive.
function CreateArchive( )
{
    var archfolder = "/sdcard/DroidScript/.archive/"; 
    app.MakeFolder(archfolder);
    //Create project zip file.
    var zip = app.CreateZipUtil();
    var fldr = "/sdcard/DroidScript";
    archname = (new Date).toISOString().slice(0,19 );
    archname = "ds"+archname.replace(/[-:]/g,"");
    archname =  archname.replace(/T/,"_");
    archname += ".zip";
    archname = app.GetModel()+"_"+archname;
    var file = archfolder + archname;
    zip.Create( file );
 
    app.ShowProgress( "Archiving..." );
    AddFolder( zip, "DroidScript", fldr );
    app.HideProgress();
    zip.Close();
 
    return file;
}
 
 
//Recursively add folder contents to zip.
function AddFolder( zip, name, fldr )
{
    txt.SetText(name);
    var list = app.ListFolder( fldr,"",0,"alphasort" );
    for( var i=0; i<list.length; i++ )
    {
        var title = list[i];
        if( !app.IsFolder( fldr+"/"+title ) )
            zip.AddFile( name+"/"+title, fldr+"/"+title );
        else if (title != ".edit" && title != ".archive")
            AddFolder( zip, name+"/"+title, fldr+"/"+title );
    }
}

function yesNoDrive_OnTouch( result ) 

    if( result=="Yes" ) 
    {
    
    var packageName = "com.google.android.apps.docs";
    var className = "com.google.android.apps.docs.shareitem.UploadSharedItemActivity";
    var action = "android.intent.action.SEND";
    var category = "android.intent.category.DEFAULT"
    var uri = null;
    var type = "multipart/*";
    var extras = [
        {name:"android.intent.extra.STREAM", type:"file", value:yesNo.fname},
        {name:"android.intent.extra.SUBJECT", type:"string", value:archname},
    ];
    
    extras = JSON.stringify( extras );
    app.SendIntent(packageName, className, action, category, uri, type, extras);
  }
}

dave finney

unread,
Apr 30, 2016, 6:59:19 PM4/30/16
to DroidScript
There is a very simple way to backup DS MP apps,

Just copy/paste prog and save in a notepad on PC

this is
fast and simple
a version saved on both phone and PC

Virtuos86

unread,
May 2, 2016, 2:10:08 AM5/2/16
to DroidScript
I use for backups TotalCommander with a plugin for Dropbox. Simple copying app's folders works good.

Dave Smart

unread,
May 26, 2016, 12:12:46 PM5/26/16
to DroidScript
The simplest way (which I use all the time) is to just use the "Share via Email" option and regularly send your self an SPK of the app you are currently working on :)

(At some point in the future we will come up with a more elegant solution)

John LaDuke

unread,
May 27, 2016, 8:29:56 AM5/27/16
to DroidScript
Actually, Dave, a "Sync with DropBox" or a "Git Push" would be just as simple if added to the same menu as "Share via Email" menu. ;-)

Gerard Hernandez

unread,
May 27, 2016, 9:12:04 AM5/27/16
to DroidScript
The interaction would be easy, integrating it into DS will take time, also that would lead to a lot of people asking for the feature for their own apps too, so it must be implemented correctly.

Mauritz Zondagh

unread,
Jul 18, 2016, 5:45:14 AM7/18/16
to DroidScript
Hi
Is it possible to open the spk file on a desktop PC, to view all the files?
I made a email to spk as a backup - want to confirm everything is there, and that the backup is working, but do not have Droidscript on desktop, also i do not want to transfer spk back to phone and then open with Mobile Droidscipt, because i have the original project already in the project list.

Am i missing something?

Thanks

Netpower8

unread,
Jul 18, 2016, 5:50:57 AM7/18/16
to DroidScript
Rename spk to zip. And open the file with winzip pr similar program. It will extract all files to the pc

Mauritz Zondagh

unread,
Jul 18, 2016, 5:56:34 AM7/18/16
to DroidScript
Thanks, not working. Get message that the file is either unknown format or damaged.
Tried opening with winrar, 7 zip
Do i need winzip specific? Winrar can also open zip files.

Maybe the file is damaged, the file emailed to me was named RCal.spk (2.97KB) in email attachment, and when i pull it down to desktop from email it is RCalc.spk (2.97 KB).msg
(msg outlook email format)

Thanks

Steve Garman

unread,
Jul 18, 2016, 8:57:30 AM7/18/16
to DroidScript
It sounds like the fille is damaged.

You should not need to use anything special. The spk is a very basic zip format.

Mauritz Zondagh

unread,
Jul 22, 2016, 5:23:16 AM7/22/16
to DroidScript
Hi,
Is the functionality on the mobile Droidscript to email a spk file working? Twice i emailed me a spk file of one of my projects in Droidscript, but when i try to unzip on desktop or open on mobile with Droidscript it says invalid file. (On the mobile a renamed the existing project, so that i can install the spk for a test).
I used the mobile app, did not try to create a spk from laptop yet.

There is nothing more i can do, only option email / spk? Something i need to set somewhere?

Steve, i can note that i installed your File Explorer spk onto my mobile, and it works 100%. So the problem is the spk file itself, not the installing part.
PS : Thank you for the File Explorer, excellent and saved me many hours.

Thanks

Steve Garman

unread,
Jul 22, 2016, 5:32:25 AM7/22/16
to DroidScript
The spks are being created ok here.

Would you like to email me one straight from DroidScript?
steve.garman[at]gmail.com

"Hello World" will do or any other app of your own.

Mauritz Zondagh

unread,
Jul 22, 2016, 5:35:00 AM7/22/16
to DroidScript
Thanks, i have send you the spk
Mauritz

Steve Garman

unread,
Jul 22, 2016, 5:42:41 AM7/22/16
to DroidScript
Maurits,
The reason I wrote

"Would you like to email me one straight from DroidScript?"

was so I could find out whether the corruption was occurring at the creation time or later.

The forwarded copy is corrupted but the email also looks very strange.

If you would like to email me one straight from DroidScript, I would be interested to compare the email.


Mauritz Zondagh

unread,
Jul 22, 2016, 5:48:40 AM7/22/16
to DroidScript
Hi Steve,

I did not forward a previous email. (i think i know what you refer to. If i receive the email send from DroidScript at my work the attachement is a *.msg (outlook message). The copy received on my mobile i a spk file)

I have send you the spk from Droidscript directly by right long clicking on the project and then select Share via email, then i select my email client Bluemail and send the message from Bluemail.
I did it again but this time with Gmail and not Bluemail. See if this works?

Thanks
Mauritz

Steve Garman

unread,
Jul 22, 2016, 5:57:35 AM7/22/16
to DroidScript
Yes, the one from Gmail works fine.

It is just a basic new project from DroidScript.

Mauritz Zondagh

unread,
Jul 22, 2016, 6:01:43 AM7/22/16
to DroidScript
OK thanks for the help.
I tested on my side by sending the spk via Droidscript/Gmail, receiving it via Bluemail on my mobile and successfully installed it into Droidscript.

So it seams that the interface between Droidscript / Bluemail for sending the spk does not work together. But it is fine, i can use gmail for the backup i want to do via spk.

Many thanks
Mauritz

Mauritz Zondagh

unread,
Jul 22, 2016, 6:27:19 AM7/22/16
to DroidScript
Just as i final comment for newbie's who needs a way to backup your code for reference.

You can also select share via email in Droidscript, but select Google Drive and not your Gmail client.

In google Drive, rename to zip, install a zip extractor if not already done, and voila - you can view your js code within drive.
The nice thing about Drive is that it does not override your previous files with the same filename - so it works excellent for backup's.

Steve Garman

unread,
Jul 22, 2016, 10:14:39 AM7/22/16
to DroidScript
Mauritz,

That is what I do.

However, most users that don't have more than one mailer, usually set mails to "always use" Gmail.

Under those circumstances, the list of apps does not come up.

Steve Garman

unread,
Jun 16, 2020, 6:17:15 AM6/16/20
to DroidScript
It may be worth mentioning that before and after making major changes to an app I usually use "Share SPK" to save to Google Drive
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages