Creating an android app that simply launches a URL in the browser
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?
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.xml
<uses-permission android:name="android.permission.INTERNET"/>
链接地址: http://www.djcxy.com/p/41964.html