2

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.

Black
  • 18,150
  • 39
  • 158
  • 271
hakkim
  • 666
  • 15
  • 36

2 Answers2

6

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);
    }
Black
  • 18,150
  • 39
  • 158
  • 271
0

You can use a web view in XML file and load your url in it

WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("http://www.google.com");