Install APK from server's shared folder in Xamarin Forms

0

I am trying to install an APK from my device. I have a way to check if there is a new version, but it keep failing when I try to install the APK.

Here's the relevant code:

    try
            {
                SharpCifs.Config.SetProperty("jcifs.smb.client.lport", "8080");

                string path = @"smb://Nascld/Share/IT/Androids/Picking.apk";
                var auth = new NtlmPasswordAuthentication("Domain", "login", "pwd");

                //Get target's SmbFile.
                var file = new SmbFile(path, auth);



                //Check if file exist
                if (file.Exists())
                {
                    Intent PromptInstall = new Intent(Intent.ActionView).SetDataAndType(Android.Net.Uri.Parse(file.GetPath()), "application/vnd.android.package-archive");
                    PromptInstall.SetFlags(ActivityFlags.GrantReadUriPermission);
                    PromptInstall.SetFlags(ActivityFlags.NewTask);
                    PromptInstall.SetFlags(ActivityFlags.ClearWhenTaskReset);
                    context.StartActivity(PromptInstall);



                }
                else
                {
                    returnValue = false;
                }
            }
            catch(Exception e)
            {
                Console.WriteLine(e.ToString());
                returnValue = false;
            }

So, I manage to find the file, get it into file, check if it exist, then create the Intent. But whenever I start it, I get an error.

No Activity found to handle Intent { act=android.intent.action.VIEW dat=smb://Domain/Share/IT/Androids/Picking.apk typ=application/vnd.android.package-archive flg=0x10000000 }01-19 17:16:22.236 I/mono-stdout(12860): Android.Content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=smb://Domain/Share/IT/Androids/Picking.apk typ=application/vnd.android.package-archive flg=0x10000000 }

at Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0006e] in :0
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0002a] in :0
at Android.Content.ContextWrapper.StartActivity (Android.Content.Intent intent) [0x00031] in :0
at Picking.Helpers.Common+<>c__DisplayClass46_0.b__0 () [0x00077] in D:\cldRefactoring\cldRefactoring\Projects\1 Presentation\Picking-4.0\Picking\Picking\Helpers\Common.cs:937
--- End of managed Android.Content.ActivityNotFoundException stack trace ---
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=smb://nascld/Share/IT/Androids/Picking.apk typ=application/vnd.android.package-archive flg=0x10000000 }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1816)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1525)
at android.app.ContextImpl.startActivity(ContextImpl.java:791)
at android.app.ContextImpl.startActivity(ContextImpl.java:768)
at android.content.ContextWrapper.startActivity(ContextWrapper.java:356)

I am at a loss. I've been searching for hours now, and I assumed it was an issue with the context, but I now believe the intent is the issue,but I can't pinpoint why, nor solve it. Thank you for your help.

c#
android
android-intent
xamarin.forms
apk
asked on Stack Overflow Jan 21, 2021 by Elgate

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0