Open Browser After Clicking Button - Android Studio

Button Click Function -

>> first you make a button on XML file or layout Design.
>> then Go to Activity Class and Define Button Property and Function.

=======================================================
public class MainActivity extends AppCompatActivity {
    private Button bt1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        bt1 = findViewById(R.id.button1);

        bt1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("enter your url"));
                startActivity(browserIntent);
            }
        });
}
}
=======================================================

>> Yellow Highlighted Code is Show How to Open External link in browser, when Clicking a Button.




No comments:

Post a Comment