Uri Popov
Uri Popov

Reputation: 2167

Unity3d Application.OpenURL on a mobile device(both Android and iOS)

So I have this method that is used on several buttons.

public void OpenURL(string url)
{
  Application.OpenURL(url);
}

It is used to open several links for the social media of the game. Twitter, facebook and instagram links open just fine. How ever when provided with the link for our website The mobile device says "Cant open pdf ("address of website"). The website itself is still "under construction" and just has a background image(defined in the css) and a Coming soon text. Why is it trying to open a pdf and how do I fix this.

P.S When testing the button in the editor it works fine and opens up a new tab on the default browser.

Upvotes: 1

Views: 16148

Answers (2)

Codemaker2015
Codemaker2015

Reputation: 15669

You might forgot to add the protocol with the URL. In the case of windows machine it will work without any issue but when we try the same thing in android mobile then we have to provide the protocol to say that it's a valid URL.

Try to use like this,

Application.OpenURL("http://<YOUR_ADRESS_HERE>");

Eg: Application.OpenURL("http://www.google.com");

If you are trying to open any document using Application.OpenURL then it won't work. Unity removed that support in latest versions. You can use AndroidOpenUrl.OpenUrl(documentUrl, dataType) for those cases.

You will get a demo and installation steps of the package from the following repository.

https://github.com/codemaker2015/Unity-Android-Files-Opener

Upvotes: 0

MadJlzz
MadJlzz

Reputation: 886

I have issued the same problem with some of my projects.

In fact, when I used Application.OpenURL with addresses like www.google.com it worked out of the box with computers but not with smartphone devices.

After hours of hair pulling, I just add the HTTP request protocol to the URL and that was it.

To comply with both computers and smartphones devices use Application.OpenURL("http://www.google.com");

Upvotes: 7

Related Questions