I'm trying my hand at developing an app for android, and the java is a bit confusing. The code I have so far is....
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButtonClick = (Button) findViewById(R.id.ButtonClick);
final String link = "htttp://www.stackoverflow.com";
ButtonClick.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
URI uri;
try {
uri = new URI("http://www.stackoverflow.com");
} catch (URISyntaxException e) {
e.printStackTrace();
}
browserIntent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(browserIntent);
}
});}}
The issue with the way the code is currently written is when I try to assign the new intent (browserIntent), uri in what I understand to be the "data" part of that object. Android Studio says that uri cannot be converted to a URI, but it's declared as a URI only a couple of lines above!
I also tried to insert a string of text, initialized above as well, which looks like...
browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(link);
This compiles fine, but when I actually click on the button it says that there is no activity to handle the intent.
So my questions in order are: 1) If I declare the URI uri variable earlier in the code, and the second property of the intent is looking for a URI, why is there an error when I simply feed it the variable uri? 2) In the second case, when I am trying to parse the string, where there is no activity to handle the intent, is this issue with ACTION_VIEW? It seems that its able to find the URI fine, however it can't actually go through with opening a browser. Perhaps 3) What is the simplest java api or java tutorial that would cover this issue that you have found or know of?