Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Image button as a hyperlink, phone call, map directions?

I have a simple app that I'm putting together for my company. I have 4 buttons that I've created but can't seem to get them to link correctly. One button should open our mobile site, another button to call us, another button to map to us, and the final button linked to our "News" site. Any help would be greatly appreciated!

like image 634
SAFCU Matt Avatar asked Sep 17 '25 06:09

SAFCU Matt


2 Answers

On your buttons, you should set OnClickListener, and to do some required actions you could see the example below:

  1. To Open a Map with Certain Location

    mapButton.setOnClickListener(new OnClickListener(){
        @Override
        public void onClick(View v) {
            Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=" + your-location-geo-address));
            startActivity(i);
        }
    });
    
  2. To call certain number

    callButton.setOnClickListener(new OnClickListener(){
        @Override
        public void onClick(View v) {
            Intent i = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + telephone-number));
            startActivity(i);
        }
    });
    
  3. To open a website

    linkButton.setOnClickListener(new OnClickListener(){
        @Override
        public void onClick(View v) {
            Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(website-address));
            startActivity(i);
        }
    });
    

Change "location-address", "telephone-number", and "website-address" with your own String value. I hope this helps.

like image 143
Muhammad Abdullah Avatar answered Sep 19 '25 21:09

Muhammad Abdullah


anmustangs answer is very good, but one thing I would like to add for the button you are making for a link to your site, where anmustangs wrote (website-address) instead of just typing in a site, it needs to put formatted correctly. For example, you can use "http://www.google.com" and yes you do need to use the quotation marks I put in there. I know I am years late to this thread but who knows who my post may help.

like image 23
Bob Smith Avatar answered Sep 19 '25 21:09

Bob Smith