# Application.OpenURL in Unity works in inspector (PC) but not in Android

I'm using unity and I've got some simple code that should work but doesn't for some reason and I'm stuck. Basically I am just trying to open up a website through a button click "On Click ()" in an application meant for android but it does not work. The code goes as follows.

public string url;

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

public void Website2(string diffURL)
{
Application.OpenURL(diffURL);
}

public void Website3()
{
}


As you can see I have three different variations of the same "Application.OpenURL" testing on three different buttons and all three do not work. Some more information:

• I have paid close attention to format the websites properly with quotation marks and "http://"
• I have already set the "Internet Access" to "require" in the player settings,
• and interestingly enough, they work in the game window when testing, it is only when I upload the apk to my android device that it does not work anymore .

The buttons register I am pressing them as evident by the slight darkening of the button press when I press on my android device but nothing happens. I have seen this question asked around but no solution to my issue has been found. Are any other build settings wrong? Any other thing I should change in Unity? API level or what?(currently 19 on min and highest installed on target)

Is there some settings I should change on my android device to allow this to happen? Because as stated earlier it works when testing through the game window on unity but not on android.

(The function "Website3()" begun to work when I rebuilt the app. No changes were made. "Website1()" and "Website2()" however still do not work on android and they work perfectly fine on unity game window.)

• Have you checked the logcat output at all to see if there’s an exception occurring at the point when you press the button? – Ed Marty Mar 8 '20 at 15:45
• @EdMarty how would I go about doing that? – EmperiumIce Mar 8 '20 at 20:04
• Search logcat on Google to find out more. – Ed Marty Mar 8 '20 at 21:55
• @EdMarty is there any particular error logs I should be checking for? There doesnt seem to be any debug checks on their documentation? – EmperiumIce Mar 8 '20 at 22:48
• Not sure really. Look for exceptions in the logs (eg. NullPointerExcrption, ActivityNotFoundException, NullReferenceException...). I would recommend just clearing the logs, pressing the button, and then immediately stopping the logs and see what shows up – Ed Marty Mar 8 '20 at 22:54

I found out the problem! So when you type out url for Application.OpenURL there are quotation marks around the URL and so I typed in the url string values (url and diffURL) the same way in the inspector for the "Website1()" and "website2()" examples, with quotation marks and all ("http://www.google.com/"). For some reason it does not work that way. I took away the quotation marks in my user string values and boom it worked (http://www.google.com/). However this still doesn't answer why "Website3()" was not working initially and then did work after I rebuilt the app even though I changed nothing. I guess it doesn't matter too much anyway since it works now.

Essentially if you are going to input a url as a string value from the inspector as opposed to hard coded into the script then DO NOT write out the url with quotation marks surrounding it.

Hopefully this helps others who may face the same issue.

Thanks to EdMarty and DMGregory.

• Please use answers to provide your solution, rather than editing the answer into the question. I've moved this answer out of your question and into this answer you thankfully left. Now you can also mark it as accepted. – doppelgreener Mar 11 '20 at 10:48
• Note that the reason you need quotation marks in code is to delineate the ends of the string literal. So if I want to print the text "Destroy(gameObject)", the compiler knows to treat the stuff in quotation marks as just literal text to print — and doesn't try to execute it as code to destroy my game object. When you're typing into an inspector, the field itself already delineates the string variable — so you don't need extra quotation marks to say "by the way, this is literal text, not programming code". – DMGregory Mar 11 '20 at 11:38

## Good for opening website to the browser

string baseUri = "https://myawesomewebsite.com"
Application.OpenURL(baseUri + "/faqs.html");
Application.OpenURL(baseUri + "/contactus.html");


## Good for opening deployed app to the Play Store

string market = "market://details?id="
Application.OpenURL(market + Application.identifier);