Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
infinite360vr's avatar
10 years ago

Unity - How to open Samsung Internet App from my Unity App

Here is a scenario, I want to redirect users to Samsung Internet Web Browser App to create a new account when they click on sign up button. Is there a way to open others app via Unity, Or can I show web view in my own app for sign up purposes. And can I somehow use the virtual keyboard in my app as well like the one in Samsung Internet App.

6 Replies

Replies have been turned off for this discussion
  • Virtual keyboard and in-app browser support aren't available yet. But you can send an intent to a web browser as described here. See the ACTION_VIEW intent:

    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(<your_url_string>));
            public static final String SAMSUNG_INTERNET_PACKAGE_NAME = "com.sec.android.app.sbrowser";
            // Extra used to match the session.
            private static final String EXTRA_SESSION = "android.support.customtabs.extra.SESSION";
            Bundle extras = new Bundle;
            extras.putBinder(EXTRA_SESSION, sessionICustomTabsCallback.asBinder());
            intent.putExtras(extras);
            intent.setData(url);
            intent.setPackage(SAMSUNG_INTERNET_PACKAGE_NAME );
            context.startActivity(intent);
    If the user doesn't have the Samsung internet browser installed (which is not uncommon), this will fail. You may want to prompt the user to install it or use a generic ACTION_VIEW intent like the following:

    try {
    Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(download_link));
    startActivity(myIntent);
    } catch (ActivityNotFoundException e) {
    Toast.makeText(this, "No application can handle this request."
    + " Please install a webbrowser", Toast.LENGTH_LONG).show();
    e.printStackTrace();
    }
  • Note: if you try to use the second approach I mentioned (ACTION_VIEW without a specific app), there is a known hang in some cases. You can avoid that by sending the intent from Unity's OnPause callback and prompting your user to take the phone out of the headset.
  • Thanks a lot for response. I have never worked with native code before, can you please tell me where should this code be placed in java file?
  • Have a look at https://forum.unity3d.com/threads/creating-a-share-button-intent-for-android-in-unity-that-forces-the-chooser.335751. You can make and send the intent from C# using Unity's AndroidJavaObject class. The calls can go in an OnPause callback, but you should show a dialog (probably in a UI canvas) telling the user to undock to make OnPause fire.
  • The code on Samsung developer website contains a lot of bugs and not even complete. So is of no use for a person who is working with Unity3D. But I was able to get help from other resources like this.

    Here is my code that works fine:

    public class My_Plugin
    {
    public static My_Plugin instance;

    public static void start()
    {
    instance = new My_Plugin();
    }

    public static void OpenURL(String url)
    {
    Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    myIntent.setPackage("com.sec.android.app.sbrowser");
    myIntent.setData(Uri.parse(url));
    UnityPlayer.currentActivity.startActivity(myIntent);
    }
    }

    Use this plugin like this:



    public class PluginsTest : MonoBehaviour 
    {
    AndroidJavaClass pluginClass ;
    void Start()
    {
    pluginClass = new AndroidJavaClass("com.library.myplugin.My_Plugin");
    pluginClass.CallStatic ("start");
    }

    public void OnButtonClicked()
    {
    pluginClass.CallStatic ("OpenURL", "https://www.google.com");
    }
    }




    Register the OnButtonClicked method to any button's onClick event listener.
    Once you press the button and then take out the phone from Gear VR. It will open the browser with given url.
    This is just a work around. Ideally I wanted to open Samsung Internet VR App without taking the phone out of Gear if that's possible
  • @vrdaveb: The above code does not work with com.sec.android.app.svrbrowser
    I use a simplified version 
    String packagename = "<ApplicationID>";
    startActivity(getPackageManager().getLaunchIntentForPackage(packagename));