Provide WebView with Url to Asset - uno-platform

In my Uno UWP project, I can view an html Asset file (w/ Content BuildAction), stored in my shared project, using the following:
var myAssetUri = new Uri("ms-appx-web:///Assets/Html/index.html");
myWebView.Navigate(myAssetUri);
However, this does not work with Android or WASM (not yet tried on other platforms). On WASM, I get a blank page. On Android, I get a page with the message:
The webpage at ms-appx-web:///Assets/Html/index.html could not be loaded because:
net::ERR_UNKNOWN_URL_SCHEME
When I look at the package folders for both platforms, I do find my html file:
WASM: bin/Debug/netstardard2.0/dist/package_.../Assets/Html/index.html
Android: (unziping my app's apk) assets/Html/index.html
so, I am guessing I'm not doing something right ... but I don't know what that might be.

The cause is simple: WebView not implemented yet on Wasm nor Skia.

This is the solution after hours investing!!
For you proyect write this line:
var myAssetUri = new Uri("file:///android_asset/Assets/Assets/Html/index.html");
This work 100%

Related

How do I load a custom Font in Xamarin using UrhoSharp?

I am trying to follow the example posted by Adam Pedley at
Introduction to UrhoSharp in Xamarin Forms but have run into a problem. In the following code block, he is loading a custom font:
private void CreateText()
{
// Create Text Element
var text = new Text()
{
Value = "Hello World!",
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
text.SetColor(Color.Cyan);
text.SetFont(font: ResourceCache.GetFont("Fonts/Anonymous Pro.ttf"), size: 30);
// Add to UI Root
UI.Root.AddChild(text);
}
The problem I have is that I don't have this font, and it isn't included anywhere in any kind of Assets folder or anything in his GitHub repository of his demo project at adamped/UrhoSharp.Demo. In fact, in spite of the allusion to a "Fonts" folder in the function call, no Fonts folder exists in his demo solution in any of the projects.
Trying to run the application results in a mono runtime error " [ERROR] FATAL UNHANDLED EXCEPTION: System.Exception: Could not find resource...".
In addition, there doesn't seem to be any means of contacting the author to ask (which I find doubly frustrating), so I am having to ask the Stack Overflow community: Where and how do I place custom font assets in my solution (his solution) so that a custom font may be used?
I am currently able to use a custom font in a standard Label with the font file being located in the /Assets folder of both my Sample.Android and Sample.UWP projects, but no combination of path or file name I have tried in the call to GetFont(...) works.
After hours of searching, I finally came across a screen shot showing the proper setup for anyone else who may run into this issue;

Xamarin.Forms embedded image not showing

There are several posts here on stackoverflow that cover this, but none are the cause. I've tried several sources including the documentation and I can not get this to work.
I'm following a tutorial by mosh on Udemy and he's showing how to use an embedded resource file.
I am working with Visual Studio 2017.
I've added a folder in the HelloWorld folder called images and placed an image called background.jpg in it.
When you right click the image and set the Build Action to EmbeddedReesource you're supposed to get a Resource Id. None is there, not even the box shows up. I'm thinking that's a new feature that was removed.
I found out the resource path is HelloWorld.images.background.jpg.
My xaml is like this:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="HelloWorld.ImagePage"
BackgroundColor="Black">
<ContentPage.Content>
<Image x:Name="image" Aspect="AspectFill" />
</ContentPage.Content>
</ContentPage>
Next, my c# code is like this:
public ImagePage ()
{
InitializeComponent ();
image.Source = ImageSource.FromResource("HelloWorld.images.background.jpg");
}
And I've tried placing the image in the android project under Resources/Drawable, but doesn't that defeat the purpose?
Any help would be great. Thanks ahead of time.
Here is my VS Solution Explorer:
This way of embedding images is still supported. Check out this page in the documentation on how to do it. These are the basic steps:
Set Build Action of the file to EmbeddedResource, you can do this in the properties of the file
Refer to the image from your PCL with a dot delimited identifier. The filename is build up like this: AssemblyName.Folder.ImageName.ext
If your image is not in a folder, you can leave is out, if it is in multiple folders, add each one separated with a dot. An example could look like this:
var embeddedImage = new Image { Aspect = Aspect.AspectFit };
embeddedImage.Source = ImageSource.FromResource("WorkingWithImages.beach.jpg");
Here the assembly (probably your project name for your PCL) is named 'WorkingWithImages' and the file is not in a folder, the file is named 'beach.jpg'. In the case of Android I think you should also mind that you do not put in hyphens or any other characters than numeric, alphabetic and underscores.
That being said, you also say:
And I've tried placing the image in the android project under
Resources/Drawable, but doesn't that defeat the purpose?
I'm not entirely sure what you mean here, but I took it that you think it defeats the purpose of a multi-platform app from a single code-base. I must disagree with you there. Although I see how you could think that, working with images is something that is very platform specific. All platforms have a very different way of showing and scaling images and it would be nearly impossible to reconcile all that for Xamarin. Having the images in the PCL like you want to do now, will completely disable the whole scaling mechanism in place and suddenly you are responsible for making it look good on all kinds of devices, resolutions and form factors. That is why I always have the images resources per platform project.

Open PDF in the PhoneGap App that is made in HTML and CSS

I have a strange problem with my iPad App in Phone Gap. The problem is that I have to open PDF document in my app through links and when I click the link which opens the PDF, it shows me the PDF document with no back link.
Hence, when I open the PDF document in my app through a link, it takes me to a dead end and there is no way I can go back to the main page of my app.
My question is that how can I have a Top-Bar, when I open a PDF which could take me back to my home page? Any internal element for the iPad may be?
Thanks a lot.
Try using the In App Browser plugin.
If you're using a later Phonegap / Cordova version (2.8.0, 2.9.0 etc) it should come with it - nothing else to install.
http://docs.phonegap.com/en/2.9.0/cordova_inappbrowser_inappbrowser.md.html#InAppBrowser
It will allow you to open the PDF in the a new 'window' that overlays your app. It has a 'Done' button that users can use to close it and return to your app when they are finished.
You would open the PDF using the In-App Browser, using something like this:
window.open('http://whitelisted-url.com/pdftoopen.pdf', '_blank');
I.e. the _blank option triggers the In-App Browser plugin. If you were to use _system instead it might open it in iBooks (just guessing there - not 100% sure if it would use iBooks).
Try prefixing https://docs.google.com/viewer?url= in the URL
like, window.open('https://docs.google.com/viewer?url=http://www.example.com/example.pdf&embedded=true', '_blank', 'location=yes');
Try this to open any kind of documents from URL using following steps:
install this plugin : cordova plugin add https://github.com/ti8m/DocumentHandler
use this code :
handleDocumentWithURL(function() { console.log('success'); }, function(error) { console.log('failure'); if (error == 53) { console.log('No app that handles this file type.'); } }, 'http://www.example.com/path/to/document.pdf');
It works for me both on Android and IOS. I used it for open images and PDF files.
Android : It opens files using system apps if available, otherwise it give an error, which you can handle.
IOS : It opens files in popup like view with Done button and Option button.
It doesn't show your docs URL.
Source is available here : https://github.com/ti8m/DocumentHandler
Thanks asgeo1,
I solved it by using window.open().
<img src="images/samplens.jpg" border="0" />
Hope it helps.
I've ended up using WebIntent
as described here. The tricky part was to modify WebIntent.java to properly identify file type:
String type = obj.has("type") ? obj.getString("type") : null;
// New code starts
Uri uri = obj.has("url") ? Uri.parse(obj.getString("url")) : null;
String extension = MimeTypeMap.getFileExtensionFromUrl(obj.getString("url"));
if(extension != null){
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
type = mimeTypeMap.getMimeTypeFromExtension(extension);
}
// New code ends
JSONObject extras = obj.has("extras") ? obj.getJSONObject("extras") : null;

After exporting a flex project, the images are broken

After completing building a flex project in Flash Builder 4.5, the project was exported using the
File -> Export Flash Builder Project.
After which some of the images stopped working (get the broken image icon). This has left me clueless and even search on the internet did not give me good answers...
I get the same problem time to time. Probably compiler / Flash Builder bug. But to be sure, you might want to check some basic things. First off: check that you have correct image urls. Secondly, ensure you are not using absolute source paths (e.g. C:\workspace\project\src\assets\images\image.png). Instead use relative path (i.e. assets\images\image.png).
If these are correct, check your build directory (default build directory for release builds in FB is bin-release) and see if the images are compiled there correctly. As I said, for some reason my FB does not always compile all the assets correctly, so sometimes I have to move them in manually. That is, you can simply drag and drop them from the source directory to the bin-release directory (although if you are using svn, you should be careful with this as it might copy also the svn metadata).
Other solutions you might want to try:
restart eclipse / FB (maybe it's simply out of memory)
delete the project from your workspace and import it again with no project information
change workspace and import the project there
I finally found the answer... made all the images bindable and just used the class to tag the images.
for example... instead of
if (draggedImage.id == "Chris" )
{
newImage.source = "assets/Chris.png";
}
changed it to
if (draggedImage.id == "Chris" )
{
newImage.source = pic3_icon;
}

Flex ItemRenderer Images not appearing at runtime

in datagrid I have an ItemRenderer (which extends UIComponent) which loads images based on a data value, eg:
_img.source = "assets/images/flags/" + value[dglistData.dataField] + ".gif";
When I run my application the images (flags) are appearing in the ItemRenderer. When I build and deploy the application into BlazeDS as an SWF file - the images do not appear. Instead there is the standard "missing icon" link that appears in Internet explorer.
As far as I can tell, my ANT build script includes the above directory "assets/images/flags/" and all the images into the SWF file.
Is this a relative path issue? Not sure, any help would be appreaciated.
Thanks
Mike
When you are assigning a path as source Flash Player is trying to load the images via HTTP requests. Therefore, embedding your images in the SWF has no effect.
There are two possible solutions. Either deploy the folder containing your images to the server and use the corresponding path as your source or embed all your images into the SWF.
A simple example for the second solution. The code assumes that value[dglistData.dataField] corresponds to one of the variables with the [Embed] metadata.
[Embed(source='assets/images/flags/Image1.png')]
private var image1:Class;
[Embed(source='assets/images/flags/Image2.png')]
private var image2:Class;
[Embed(source='assets/images/flags/Image3.png')]
private var image3:Class;
// access the image like this...
_img.source = this[value[dglistData.dataField]];

Resources