Search code examples
javaandroidxmlandroid-studiomobile-application

Redirect to a webpage while opening an android app


I need to develop an app which redirects users to my website right after the app was started.

Thats all I want in my mobile app.

I am using Android studio but I am not familiar with XML. So I am stuck there. Which code should I write to do this redirection? Hope you all can help me. Thank you.


Solution

  • First you need to import this:

    import android.content.Intent; 
    import android.net.Uri;
    

    In your MainActivity.java class, OnCreate Method you may add

     protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            Intent i = new Intent(
                Intent.ACTION_VIEW,
                Uri.parse("http://www.google.com")
            );
    
    // Starts Implicit Activity
            startActivity(i);
        }