[英]starting an apk in a android delphi seattle application error
For several reasons I don't want to use the Google Play mechanism to upgrade an android application.出于多种原因,我不想使用 Google Play 机制来升级 android 应用程序。 So I decided to make my own system to download and upgrade an android application.
于是决定自己做一个系统下载升级一个android的应用。
Step 1: download the update .apk
file.第 1 步:下载更新
.apk
文件。
Step 2: put a button in the original application so a user can click on it to start the .apk
for upgrade.第 2 步:在原始应用程序中放置一个按钮,以便用户可以单击它以启动
.apk
进行升级。
The following code is giving me an error.以下代码给我一个错误。
procedure TfrmUpdateProgram.DoUpgrade;
{$IF DEFINED(IOS) or DEFINED(ANDROID)}
var Intent : JIntent;
{$ELSE}
{$ENDIF}
begin
{$IF DEFINED(IOS) or DEFINED(ANDROID)}
Intent := TJIntent.Create;
Intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
Intent.addFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK);
Intent.setDataAndType(StrToJURI(newAPKFile), StringToJString('application/vnd.android.package-archive'));
SharedActivityContext.startActivity(Intent);
Application.Terminate;
{$ELSE}
ShellExecute(0, PWideChar('Open'), PWideChar(newAPKFile), nil, nil, SW_HIDE);
{$ENDIF}
end;
android.content.activitynotfoundexception: No activity found to handle intent {act=android.intent.action.view dat=/storage.....update.apk typ=application/vnd.android.package-archive flg=0x1000000}
android.content.activitynotfoundexception:找不到处理意图的活动 {act=android.intent.action.view dat=/storage.....update.apk typ=application/vnd.android.package-archive flg=0x1000000}
Any thoughts?有什么想法吗?
Try removing the call to Intent.addFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK)
, it is not strictly needed. 尝试删除对
Intent.addFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK)
的调用,这并不是严格需要的。
Make sure the .apk
file is world-readable before launching the Intent
, unless you store it to a public external folder. 启动
Intent
之前,请确保.apk
文件可被世界读取,除非将其存储到公共外部文件夹中。 And make sure it is accessible via a file:
URI. 并确保可以通过以下
file:
访问它file:
URI。
And make sure your Android device is configured to allow apps to be installed from unknown sources. 并确保将您的Android设备配置为允许从未知来源安装应用程序。
var
Path: JString;
Name: JString;
F: Jfile;
Intent: JIntent;
FileName, DestFileName: string;
FileName := System.IOUtils.TPath.GetDownloadsPath + PathDelim + 'myAPK_name.apk';
Intent := TJIntent.Create;
Intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
if TJBuild_VERSION.JavaClass.SDK_INT >= TJBuild_VERSION_CODES.JavaClass.N then
begin
lFile := TJFile.JavaClass.init(StringToJString(FileName));
Intent.setFlags(TJIntent.JavaClass.FLAG_GRANT_READ_URI_PERMISSION + TJIntent.JavaClass.FLAG_GRANT_WRITE_URI_PERMISSION);
Intent.addFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK);
//This line used to be in Delphi 10.4
//Data := TJFileProvider.JavaClass.getUriForFile(TAndroidHelper.Context,StringToJString('com.embarcadero.BarcodexMS.fileprovider'), lFile);
//Use Following line in Delphi 11.1
Data := TJcontent_FileProvider.JavaClass.getUriForFile(TAndroidHelper.Context,StringToJString(JStringToString(TAndroidHelper.Context.getApplicationContext.getPackageName) + '.fileprovider'), lFile);
end
else
begin
Data := TJnet_Uri.JavaClass.parse(StringToJString('file://' + FileName));
end;
Intent.setDataAndType(Data, StringToJString('application/vnd.android.package-archive'));
TAndroidHelper.Activity.startActivity(Intent);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.