Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating an android app that simply launches a URL in the browser

Tags:

android

I happen to have a mobile-friendly web app, but my users desperately want to install it to their app drawer :/ I have some experience with Java, the new Android Studio, and I see some instructions on this stackoverflow question, but I'm unsure where this code belongs:

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);

Putting it in the onCreate method of the default action yields errors that suggest that's the wrong place for an intent. Where would be a good place to execute such an intent?

like image 319
blaha Avatar asked Dec 20 '22 03:12

blaha


1 Answers

For Your reference, i tried this code,

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Window;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Intent browserIntent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("http://www.google.com"));
        startActivity(browserIntent);
    }

}

In Manifest's xml (e.g. AndroidManifest.xml) add

 <uses-permission android:name="android.permission.INTERNET"/>

Example:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="...">

    <uses-permission android:name="android.permission.INTERNET" />

    <application ...>
      ...

    </application>

</manifest>
like image 140
Aerrow Avatar answered May 04 '23 00:05

Aerrow