I'm implementing a backend for testers with EmbedIO (Github here). It is working beautifully with iOS. But in Android I can't find a solution.
In iOS I create this dependency from the Xamarin project:
public class WebServer : Interfaces.IWebServer
{
public IWebModule CreateWebModule()
{
return new Unosquare.Labs.EmbedIO.Modules.StaticFilesModule(NSBundle.MainBundle.ResourcePath);
}
}
In this function in iOS I can use NSBundle.MainBundle.ResourcePath but I can't find an equivalent for Android. Any ideas? Thank you in advance.
I'm not familiar with mobile development, but maybe you can try the ResourceFilesModule. This module is similar to StaticFilesModule but using resources from an assembly.
It seems it doesn鈥檛 work. I have a similar issue with UWP: I can have a instance of the webserver but I can鈥檛 reach the page or I receive a blank screen.
I pass the Assembly and the path of assets folder.
The 'resourcePath' argument is the full path to the resource including the namespace.
For example, if your assembly contains a Program class, a Resources folder and the default namespace is MyCompany.MyApp:
var moduleInstance = new ResourceFilesModule(typeof(Program).Assembly, "MyCompany.MyApp.Resources");
Maybe you need some background. I'm creating a backend for Xamarin and I have projects for iOS, Android, UWP and macOS.
In UWP I have some files in a folder called Webserver under the Assets folder. I want to show this files. I wrote this code:
public IWebModule CreateWebModule()
{
StorageFolder appInstalledFolder =
Windows.ApplicationModel.Package.Current.InstalledLocation;
string pth = Path.Combine(appInstalledFolder.Path, "Assets\\Webserver");
return new Unosquare.Labs.EmbedIO.Modules.StaticFilesModule(pth);
}
I start the WebServer like that:
var webServer = new WebServer(urlPrefixes);
webServer.RegisterModule(new WebApiModule());
webServer.Module<WebApiModule>().RegisterController<TestController>();
webServer.RegisterModule(fileModule);
await webServer.RunAsync();
This is working with iOS.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.