码迷,mamicode.com
首页 > Windows程序 > 详细

Delphi 安装apk

时间:2019-11-26 13:31:10      阅读:260      评论:0      收藏:0      [点我收藏+]

标签:data   oid   read   jin   The   archive   pat   ack   ant   

procedure ToInstallApk(filename: string);
var
   aFile: Jfile;
   Intent: JIntent;
begin
      Try
          aFile := TJfile.JavaClass.init(stringtojstring(DownPath),stringtojstring(filename));
          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(applicationnd.android.package-archive));
          SharedActivityContext.startActivity(Intent);
      Except
      End;
end;


procedure ToInstallApk70(filename: string);
var
  LFile: JFile;
  LIntent: JIntent;
  LNet_Uri: Jnet_Uri;
begin
  if not TOSVersion.Check(7, 0) then
  begin
       ToInstallApk(filename);
       exit;
  end;
  LFile := TJFile.JavaClass.init(StringToJString(ExtractFilePath(DownPath)), StringToJstring(ExtractFileName(filename)));
  LIntent := TJIntent.Create;
  if TOSVersion.Check(8, 0) then
    LIntent.setAction(TJIntent.JavaClass.ACTION_INSTALL_PACKAGE)
  else
    LIntent.setAction(TJIntent.JavaClass.ACTION_VIEW);
  LIntent.addFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK);
  if TOSVersion.Check(7, 0) then
  begin
    // fix: android.os.FileUriExposedException: exposed beyond app through Intent.getData()
    // Project -> Options -> Application -> Entitlement List -> Secure File Sharing -> Check it
    LIntent.addFlags(TJIntent.JavaClass.FLAG_GRANT_READ_URI_PERMISSION);
    LNet_Uri := TJFileProvider.JavaClass.getUriForFile(TAndroidHelper.Context,
      StringToJString(JStringToString(TAndroidHelper.Context.getPackageName) + .fileprovider), LFile);
  end
  else
    LNet_Uri := TJnet_Uri.JavaClass.fromFile(LFile);
  LIntent.setDataAndType(LNet_Uri, StringToJString(applicationnd.android.package-archive));
  TAndroidHelper.Context.startActivity(LIntent);
end;

 

Delphi 安装apk

标签:data   oid   read   jin   The   archive   pat   ack   ant   

原文地址:https://www.cnblogs.com/kinglandsoft/p/11934682.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!