I've read how to create a simple app that launches a website in the phone's external browser in this post. I followed those steps, yet my simple App keeps crashing.
I'm trying to create the absolute simplest possible app with the highest compatibility which simply opens a URL in the external browser of the phone.
These were my exact steps:
- Installed Eclipse ADT with the Android SDK from Android's official download site with all the SDK packages listed here.
- Created a new "Android Application Project".
- Set the Minimum Required SDK to API 7: Android 2.1 (Eclair) (that's the lowest API version that allowed the creation of an Activity)
- Left the Target SDK and Compile With to the default API 21: Android $.X (L Preview)
- Set the Theme to None.
- Left everything as default in the "Configure Project" step.
- Left everything as default in the "Configure the attributes of the icon set" step.
- Under "Create Activity", I selected "Empty Activity".
- Left everything as default in the "Creates a new empty activity" step.
- Clicked "Finish"
- In MainActivity.java,
I replaced:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
With:
protected void onCreate(Bundle savedInstanceState) {
String url = "http://www.YOUR-URL.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
- I added the two lines
import android.content.Intent;
andimport android.net.Uri;
abovepublic class MainActivity extends Activity {
.
Saved the file, ran it, and then installed the MyFirstApp.apk (found in /workspace/MyFirstApp/bin/) on my phone
Launched the App on my phone, it asked which browser to use, and I selected "Chrome" and "Always".
Now, every time I open the App on my phone, it will launch the URL in Chrome, but as it's launching Chrome, I get an error saying "Unfortunately, My First App has stopped."
I've tried to create the simplest App possible, and yet it crashes. The above are the exact steps I took. Where did I go wrong?