使用xamarin在C#上安装apk吗?

问题描述 投票:0回答:1

我正在使用C#编码的应用程序。我也使用Visual Studio XAMARIN和我的Android手机。

我想以编程方式安装apk。我以编程方式从网上下载了一个apk(昨天解决了这里的帮助),现在我尝试安装apk文件。我发现了这个:Android: install .apk programmatically

但这是在Java中,我不能使用java作为我的应用程序。我尝试在C#中这样做,但失败了。

这是我试图使用的代码:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(newFile(Environment.getExternalStorageDirectory() + "/download/" + "app.apk")), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

但我不能使用像uri.fromFile等的东西。另外(我不知道它在哪里)我读到有人说它甚至不可能在C#中做到这一点,现在我不知道该相信什么。

c# .net visual-studio xamarin
1个回答
0
投票

我使用了以下内容: -

        Intent promptInstall = new Intent(Intent.ActionView).SetDataAndType(Android.Net.Uri.FromFile(new Java.IO.File(Android.OS.Environment.ExternalStorageDirectory + "/download/" + filename)), "application/vnd.android.package-archive");
        promptInstall.AddFlags(ActivityFlags.NewTask);
        Android.App.Application.Context.StartActivity(promptInstall);

但是,自从将api更新到28(Android 9.0)后,这已不再适用,我正在寻找自己的解决方案....

© www.soinside.com 2019 - 2024. All rights reserved.