- Home /
How to open unity desktop app from web browser?
Hello Friends,
Actually I am working on a PC/Mac game and I have integrated a payment gateway also. What I want is that after payment success it should automatically open the application.
Currently if a user taps "Pay" button then he/she is take to payment page which gets open in a browser. then after payment he/she has to manually return to app. If any one has answer please help me. Thanks in advance.
Answer by LRG · Jan 13, 2015 at 10:30 AM
I don't think there is any built-in way in Unity to do this.
You first need to be able to detect purchase completions. This is relatively easy, as you can just signal the program from the server when paypal reports success.
Opening the App again is harder, and I can think of some alternatives:
Open new browser, close it after buying
You would need to ensure that the payment page is opened in a new browser window, and that tabs and URL bar is disabled. That way you should be able to close it after the purchase is done without annoying the user by closing its main browser window. Once it is closed, if the user did not meanwhile switch to other window, your program should automagically recover focus. You can start the browser as a child process to close it easily.
This will need further work, but for instance, to open a Chrome new window you can:
// Requires using the System.Diagnostics namespace
Process proc = new Process();
proc.StartInfo.FileName = @"chrome";
proc.StartInfo.Arguments = @"unity3d.com --new-window";
proc.Start();
Once that window is closed, focus should return on its own.
Explicitly switch focus again once the payment is done
This can be done through low level WINAPI functions such as SwitchToThisWindow. However, they tend to not work very realiably, and you will need plugins / pinvoke to use it, so unless you can find a better one, I would try the first approach.
Thanks LRG , How can I open a new window from unity app . All I know is Application.OpenUrl.
Added a Process.Start example. Though it will need some work (particularly, it won't work if chrome is not installed).
but desktop app gets $$anonymous$$imised in background. Even if we close the browser it will not help.
Your answer
![](https://koobas.hobune.stream/wayback/20220613180258im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How do i make my enemy attack my player? 0 Answers
Payment with Credit on PayPal possible? 1 Answer
System.IO.DriveInfo returns wrong disk space values on Mac 1 Answer