zoukankan      html  css  js  c++  java
  • 安卓APP在线升级

    安卓APP在线升级

    通过IDHTTP组件在线下载APP到手机中,然后自动安装这个APP程序。

    1)在线下载APP程序

    需引用单元: 

    {$IFDEF ANDROID} 
    FMX.Helpers.Android, Androidapi.JNI.GraphicsContentViewText, 
    Androidapi.JNI.Net, Androidapi.JNI.JavaTypes; 
    {IFDEF}
    procedure TForm1.Button2Click(Sender: TObject); 
    var 
    caminho_d: string; 
    MyFile: TFileStream; 
    begin 
    //verifica se ja existe para apagar e criar novamente 
    if FileExists(GetSharedDownloadsDir+’/PJMOBILE.apk’) then 
    DeleteFile(GetSharedDownloadsDir+’/PJMOBILE.apk’);
    // definir o link 
    caminho_d:= ‘http://susite.com.br/download/APP.apk‘; // aqui defini um caminho pard鉶 pro download , pode ser trocado por um edit, etc
    MyFile := TFileStream.Create(GetSharedDownloadsDir+’/APP.apk’, fmCreate); // local no celular e nome do arquivo com a extens鉶, onde vai salvar. 
    try 
    IdHTTP1.Get(caminho_d, MyFile); // fazendo o download do arquivo e salva no celular 
    finally 
    MyFile.Free; 
    end; 
    end;
    procedure TForm1.IdHTTP1Work(ASender: TObject; AWorkMode: TWorkMode; 
    AWorkCount: Int64); 
    begin 
    ProgressBar1.value := AWorkCount; 
    Application.ProcessMessages; 
    end;
    procedure TForm1.IdHTTP1WorkBegin(ASender: TObject; AWorkMode: TWorkMode; 
    AWorkCountMax: Int64); 
    begin 
    ProgressBar1.value := 0; 
    ProgressBar1.Max := AWorkCountMax; 
    Label1.Text := ‘开始下载’; 
    end;
    procedure TForm1.IdHTTP1WorkEnd(ASender: TObject; AWorkMode: TWorkMode); 
    begin 
    ProgressBar1.Value := ProgressBar1.Max; 
    Label1.text := ‘下载完成’; 
    end;
    

      

    2)安装下载的APK

    procedure TForm1.Button1Click(Sender: TObject); 
    var 
    aFile:Jfile; 
    Intent:JIntent; 
    begin
    aFile:=TJfile.JavaClass.init(stringtojstring(GetSharedDownloadsDir),stringtojstring(‘APP.apk’)); 
    Intent := TJIntent.Create ; 
    Intent.setAction(TJIntent.JavaClass.ACTION_VIEW); 
    Intent.addFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK); 
    Intent.setDataAndType(TJnet_Uri.JavaClass.fromFile(aFile),StringToJString(‘application/vnd.android.package-archive’)); 
    SharedActivityContext.startActivity(Intent); 
    end;
    

      

  • 相关阅读:
    CodeForces 659F Polycarp and Hay
    CodeForces 713C Sonya and Problem Wihtout a Legend
    CodeForces 712D Memory and Scores
    CodeForces 689E Mike and Geometry Problem
    CodeForces 675D Tree Construction
    CodeForces 671A Recycling Bottles
    CodeForces 667C Reberland Linguistics
    CodeForces 672D Robin Hood
    CodeForces 675E Trains and Statistic
    CodeForces 676D Theseus and labyrinth
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/10908534.html
Copyright © 2011-2022 走看看