Created
July 11, 2020 14:36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.tanay.thundercipher.browserintents; | |
import androidx.appcompat.app.AppCompatActivity; | |
import android.content.Intent; | |
import android.net.Uri; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.Toast; | |
public class MainActivity extends AppCompatActivity { | |
Button fbButton, youtubeButton, instaButton; | |
public void clickedButton(String url) | |
{ | |
Intent intent = new Intent(Intent.ACTION_VIEW); | |
intent.setData(Uri.parse(url)); | |
try | |
{ | |
startActivity(Intent.createChooser(intent, "Choose a Browser")); | |
} | |
catch(Exception e) | |
{ | |
Toast.makeText(getApplicationContext(), "Couldn't open the link!", Toast.LENGTH_SHORT).show(); | |
} | |
} | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
fbButton = (Button)findViewById(R.id.fbButton); | |
instaButton = (Button)findViewById(R.id.instaButton); | |
youtubeButton = (Button)findViewById(R.id.youtubeButton); | |
fbButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) | |
{ | |
clickedButton("https://www.facebook.com/"); | |
} | |
}); | |
instaButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) | |
{ | |
clickedButton("https://www.instagram.com/"); | |
} | |
}); | |
youtubeButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) | |
{ | |
clickedButton("https://www.youtube.com/"); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment