//Delete files named filezip.zip
// Add jpreferences component (Android Bridges Extra)
// Add URI verification
procedure AndroidModule1.zip;
///// variables, etc
begin
///// ......here the code for compressing files generating "filezip.zip"
// Here check if the URI already exists.
// If URI does not exist then create "filezip.zip"
// If URI exists then open file "filezip.zip" and it will be overwritten
if Preferences1.GetStringData('uri','') <> '' then self.RequestOpenFile(Self.GetEnvironmentDirectoryPath(dirDownloads),'application/zip' ,112) else Self.RequestCreateFile(Self.GetEnvironmentDirectoryPath(dirDownloads),'application/zip','filezip.zip', 111);
end;
// Here is where we first register the URI in preferences after "Create intent"
procedure TAndroidModule1.AndroidModule1ActivityResult(Sender: TObject;
requestCode: integer; resultCode: TAndroidResult; intentData: jObject);
var arrayb: Tdynarrayofjbyte;
treeUri : jObject;
fs:tfilestream;
begin
if intentData = nil then
begin
ShowMessage('Sorry... data nil received...');
Exit;
end;
treeUri:= IntentManager1.GetDataUri(intentData);
if requestCode = 111 then //create file
begin
// Save URI
Preferences1.SetStringData('uri',UriToString(treeUri));
FS := TFileStream.Create(GetEnvironmentDirectoryPath(dirDownloads)+'/filezip.zip', fmOpenRead or fmShareDenyWrite);
SetLength( arrayb, fs.Size); fs.Position:=0;
Fs.Read(arrayb[0], fs.Size);
SaveBytesToUri(arrayb,treeUri);
FS.Free;
end;
if requestCode = 112 then //open file
begin
FS := TFileStream.Create(GetEnvironmentDirectoryPath(dirDownloads)+'/filezip.zip', fmOpenRead or fmShareDenyWrite);
SetLength( arrayb, fs.Size); fs.Position:=0;
Fs.Read(arrayb[0], fs.Size);
SaveBytesToUri(arrayb,treeUri);
FS.Free;
end;
end;