I am pretty new to this and i was trying to create a button that opens up Google in browser:
Button googleBtn = (Button) findViewById(R.id.googleBtn);
googleBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String google = "https://www.google.com";
Uri webaddress = Uri.parse(google);
Intent gotoGoogle = new Intent(Intent.ACTION_VIEW, webaddress);
if (gotoGoogle.resolveActivity(getPackageManager()) != null){
startActivity(gotoGoogle);
}
}
});
It seems like the value i get in the if statement is null so the app skips the startActivity method. (i tried running it on an emulator and on my phone).