.NET MAUI Blazor - Android app displaying content of external url

542 views Asked by At

I am building android TV app with .NET MAUI Blazor. All this app supposed to do is to display external url content. Basically it wants to act as a web browser and navigate to a specific url.

Solutions I've already tried:

I used an iframe in app's html but this causes issues with oAuth authentication user needs to go through. Identity Server I use doesn't like iframes.

I used MAUIs NavigationManager.NavigateTo(url, true); that sends an intent to Android device's OS and it requires browser to be installed on the device to work. If there is no browser installed (which is the default case) I only get toast displayed by device informing that I have no app that can do that action.

I have also tried replacing <BlazorWebView HostPage="wwwroot/index.html"> in MainPage.xaml with HostPage="https://www.[mypage].com/index.html" but this causes app to render page with message "There is no content...".

Is there a way I can use my app as a web browser and render html from an external url?

Any help will be very much appreciated.

1

There are 1 answers

4
Alexandar May - MSFT On

Yes, you can use NavigationManager.NavigateTo("PageToRedirect") to navigate to an external url. However, this will call the device default browser to navigate to the page, so it needs browser to be installed on the device initially.

Here's the sample code for your reference:

@page "/counter"
@inject NavigationManager MyNavigationManager

<button type="button" @onclick="()=>click()">Navigate to external page</button>


@code {

    async Task click()
    {
         MyNavigationManager.NavigateTo("https://learn.microsoft.com/en-us/dotnet/maui/");
    }
}


Update:

Since there's no default browser on the device initially, alternatively, we have done that app using Android Studio instead to fix it.