在Delphi中更新Android移动应用程序而不提示
我正在尝试更新我正在开发的移动应用程序,而无需额外的用户输入。该应用程序应该在没有任何用户有权访问该设备的情况下运行,我需要一种方法来更新它。由于它会同时在数十台设备上运行,因此遗憾的是,仅手动将其换出并不是一种选择,就像使用 PlayStore 一样。
到目前为止,我已经有了这段代码,可以让我启动更新,但用户每次仍然需要确认。
procedure TForm1.StartActivityA(const AFileName: string);
var
Intent: JIntent;
Data: Jnet_Uri;
begin
try
Intent := TJIntent.Create;
Intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
Intent.setFlags(TJIntent.JavaClass.FLAG_GRANT_READ_URI_PERMISSION);
Data := TAndroidHelper.JFileToJURI(TJFile.JavaClass.init(StringToJString(AFileName)));
Intent.setDataAndType(Data, StringToJString('application/vnd.android.package-archive'));
TAndroidHelper.Activity.startActivity(Intent);
except
on E: Exception do
begin
TDialogService.ShowMessage(e.message);
end;
end;
end;
由于应用程序应该运行的设备无法访问用户输入,因此我正在寻找一种解决方案,允许我执行我所描述的操作(最好同时关闭并重新启动应用程序,但我还没有得到这一点到目前为止,任何有关这一点的指示也将不胜感激)。
我找到了这篇文章和这篇文章关于在Android上静默安装/更新应用程序,但我不知道如何在Delphi代码中执行命令。 这个看起来可以用我现在拥有的代码来做到这一点,如果设备已root,但我不确定我是否理解正确。
据我了解,执行这样的命令需要设备被root。这是正确的吗?
这是正确的方法还是还有另一种方法(理想情况下不需要根设备,但如果没有其他方法,我可以管理)?
I am trying to update a mobile app I am working on without additional user input. The app is supposed to run without any users having access to the device and I need a way to update it. Since it will run on dozens of devices at once, just manually swapping it out is sadly not an option, as is making use of the PlayStore.
So far I have this code that allows me to initiate the update, but the user still needs to confirm it each time.
procedure TForm1.StartActivityA(const AFileName: string);
var
Intent: JIntent;
Data: Jnet_Uri;
begin
try
Intent := TJIntent.Create;
Intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
Intent.setFlags(TJIntent.JavaClass.FLAG_GRANT_READ_URI_PERMISSION);
Data := TAndroidHelper.JFileToJURI(TJFile.JavaClass.init(StringToJString(AFileName)));
Intent.setDataAndType(Data, StringToJString('application/vnd.android.package-archive'));
TAndroidHelper.Activity.startActivity(Intent);
except
on E: Exception do
begin
TDialogService.ShowMessage(e.message);
end;
end;
end;
Since the devices the app is supposed to run on won't be accessible for user input, I am searching for a solution that allows me to do what I described (preferable while also closing and restarting the app, but I haven't gotten that far yet. Any pointers towards that would also be appreciated).
I found this post and this post about installing/updating an app on Android silently, but I can't figure out how to execute the commands in Delphi code. This one makes it look like it might be possible to do it with the code I have now, if the device is rooted, but I am not sure I understand it correctly.
And as far as I understand it, executing commands like this requires the device to be rooted. Is that correct?
Is this the correct approach or is there another one (ideally without the need to root the device, but I can manage, if there is no other way)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论