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;
    

      

  • 相关阅读:
    linux-01Red Hat Enterprise Linux 7(RHEL7)配置静态IP地址
    Linux下Tomcat重新启动
    获取root权限
    -save 和 --save-dev的区别
    周五的听歌时间
    十月第二周计划
    国庆计划
    周末计划
    前端基础进阶系列
    前端基础进阶(二):执行上下文详细图解
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/10908534.html
Copyright © 2011-2022 走看看