Android instance-idhttp download (and implement automatic installation)

Source: Internet
Author: User instance-idhttp download (and implement automatic installation) 

Related information:

1. Group No. 383675978

2. Runtime prompt "Connection closed gracefully" error cause and resolution Http://

3. The compile-time prompt "[Exec Error] The command ... exited with code 1." Error cause unknown, workaround delete androidsdk, download new version, introduce new version of SDK.

Example Source:

  1 unit Unit1; 2 3 Interface 4 5 uses 6 system.sysutils, System.types, System.uitypes, System.classes, system.variants, 7 FMX. Types, FMX. Controls, FMX. Forms, FMX. Graphics, FMX. Dialogs, 8 FMX. Controls.presentation, Fmx.stdctrls, FMX. Objects, 9 system.ioutils, Idbasecomponent, Idcomponent, Idtcpconnection, Idtcpclient,,//tjnet_ URI using one Androidapi.JNI.JavaTypes,//jfile using the androidapi.jni.graphicscontentviewtext,//jintent using the Androidapi.hel Pers,//stringtojstring using the Idhttp;//tpath with the type TFORM1 = Class (Tform) Label1:tlabel; Progressbar1:tprogressbar; Label2:tlabel; Button1:tbutton; Idhttp1:tidhttp; Procedure Button1Click (Sender:tobject); Procedure Idhttp1work (Asender:tobject; Aworkmode:tworkmode; (Aworkcount:int64); Procedure Idhttp1workbegin (Asender:tobject; Aworkmode:tworkmode; Aworkcountmax:int64); Procedure Idhttp1workend (Asender: TObject; Aworkmode:tworkmode); Private declarations {private} to Isdown:boolean; function downfilepath:string; Public declarations} The "test.apk"; Form1:tform1 var; Implementation: {$R *.FMX} + {$R *. NMXHDPIPH.FMX ANDROID} procedure Tform1.button1click (Sender:tobject); surlpath,sfilepath:string var; Wuyi Ofile:tfilestream; Isdown begin: = True; Sfilepath: = Downfilepath + FileName; If FileExists (Sfilepath) then//To determine if the previous file exists in the DeleteFile (Sfilepath); *//surlpath:= ' ';//file (with Baidu Cloud Test) 59//originally wanted to use Baidu cloud, I 艹, Do not know why Baidu cloud download, the hint "connection closed gracefully" surlpath:= ' ';//file (with Baidu Cloud test) Ofile: = Tfilestream.create (Sfilepath, fmcreate); Files saved after download the path of try progressBar1.Value: = 0; Idhttp1.Get (Surlpath, ofile); except to the end;; The end; the function TForm1.DownFilePath:string; The Result: = Tpath.getdownloadspath + Pathdelim; The end; Procedure Tform1.idhttp1work (Asender:tobject; Aworkmode:tworkmode; Aworkcount:int64); progressBar1.Value begin: = Aworkcount; The end; Bayi procedure Tform1.idhttp1workbegin (asender:tobject; Aworkmode:tworkmode; Aworkcountmax:int64); progressBar1.Value begin: = Aworkcountmax; The end; Procedure Tform1.idhttp1workend (Asender:tobject; Aworkmode:tworkmode); The $IFDEF ANDROID} ofile:jfile Var; Ointent:jintent; Isdown {$ENDIF} 94 begin {$IFDEF ANDROID} 96//download completed automatically after the installation of the "if" and then 98 begin Try100 Ofile: = TJ File. Javaclass.init (Stringtojstring (Downfilepath), stringtojstring (FileName)); 101 Ointent: = tjintent.create;102 OI Ntent.setaction (TJIntent.JavaClass.ACTION_VIEW); 103 Ointent.addflags (TJINTENT.JAVACLASS.FLag_activity_new_task); 104 Ointent.setdataandtype (TJnet_Uri.JavaClass.fromFile (ofile), stringtojstring (' Application/ '); sharedactivitycontext.startactivity (ointent); 106 Except107 En d;108 end;109 {$ENDIF}110 end;111-end.

Android instance-idhttp download (and implement automatic installation)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.