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

12,748

Solution 1

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.

Solution 2

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.

Share:
12,748

Related videos on Youtube

SAFCU Matt
Author by

SAFCU Matt

Updated on May 04, 2022

Comments

  • SAFCU Matt
    SAFCU Matt almost 2 years

    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!

    • Mark B
      Mark B over 13 years
      What have you accomplished so far? Where are you having trouble?
  • SAFCU Matt
    SAFCU Matt over 13 years
    Where do I put my onclicklistener code? Also, how should the code for my button look in my main.xml file? I'm ridiculously new to this, so I apologize for not knowing what the heck I'm talking about!
  • Muhammad Abdullah
    Muhammad Abdullah over 13 years
    using buttons are pretty basic, have you checked Android SDK's code samples? There are a lot of samples using buttons there. developer.android.com/resources/samples/ApiDemos/index.html