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

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!

On your buttons, you should set OnClickListener, and to do some required actions you could see the example below:
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);
}
});
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);
}
});
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.

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.

Related

Using an intent to forward users to twitter app with pre-determiend search keyword

I want to be able to switch between my app and twitters app to show a search for a pre-determined hashtag.
I have an on click listener & sending the user to the twitter app... loading the tweets and allowing the discussion of that hashtag. There is the logic but how can I do this? What I get now is just my feed and a drop down list of previous searches.
Here is the listener & intent code:
final Button button = (Button) view.findViewById(R.id.C_Twitter_Button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("twitter://search?f=realtime&q=%23KeyWord"));
startActivity(intent);
}catch (Exception e) {
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("https://twitter.com/search?f=realtime&q=%23KeyWord")));
}
}
});
Can anyone offer me a solution?
Thanks
The search query was wrong :(
The solution is to use the following url to search the twitter app:
twitter://search?query=%23hashtag
Cheers

How to add a registration page to log-in page it?

I am a new android developer trying to create a log-in and register page. I have created both Log-in and Registration pages but i don't know how to add the registration page with the main log-in interface. I have tried to add it but I don't know how to do it. Can anyone let me clear on how to add a page X with another page Y.
Your answers to guide me are welcome.
Create a button in login page suppose btn_login.Then
btn_login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i=new Intent(Loginpage.this,Registration.class);
startActivity(i);
}
});
In this way you can connect two pages using Intent.
For this you can make use of Intents ,Assuming that you have two activities and A button named buttonReg
1.Login Page (Login.java)
2.Registration Page(Register.java)
Create an Intent
For the register page like like
Intent in=new Intent(getApplicationContext(),Register.class);
and start activity in the button click like
buttonReg.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v)
{
startActivity(in);
}
});
And do not forget to add the Activity to your Manifest.xml
For more information about intents goto this tutorial

Calling by Clicking the Number -- Android

I am trying to have it so that when the phone number is clicked, it makes a call. The phone number is displaying correctly, but nothing happens when I click it.
Why is this not working?
tvInfo.setText(Html.fromHtml("<a href='tel:15555555555'><b>(555) 555-5555</b></a>"));
Let me know if more information is needed. Thanks!
Try looking at Linkify. Set the phone number normally with setText, and then use Linkify.
tvInfo.setText("(555)555-5555");
Linkify.addLinks(tvInfo, Linkify.PHONE_NUMBERS);
Try this:
call.setText(Html.fromHtml("<u>" + "9999999999" + "</u>"));
call.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
number = call.getText().toString();
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + number));
startActivity(intent);
}
});

Android about button to rate on market

I am little confused with this code am looking for somenthing similar i have a button that i want it to say rate and when click it takes you to the android market where the user can rate my application, please help
Button bRate = (Button) findViewById(R.id.button7);
bRate.setOnClickListener(new View.OnClickListener() {
//plus the code on the top here is my idea of the code
}
Elipse is saying something is wrong and I understand that iI need to put my market link but the button still doesn't work
I couldn't post it on the same page here is the link for the original question
Use application to rate it on market
You have just add your app package name...
https://play.google.com/store/apps/details?id=your packagename
And call using Intent.ACTION_VIEW
String str ="https://play.google.com/store/apps/details?id=com.zeustechnocrats.quickfoods";
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(str)));
This was helpful for me to do the same thing using an image button. here the code I used.
final ImageButton mybutton = (ImageButton) findViewById(R.id.imageButton);
mybutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String str ="https://play.google.com/store/apps/details?id=ws.crandell.newspaperpuzzles";
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(str)));
}
});
Example code you can use.
Change your_package_name to your.package.name. E.g. com.example.myapp
Java File:
public void ratebutton(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW)
.setData(Uri
.parse("https://play.google.com/store/apps/details?id=your_package_name"));
startActivity(intent);
}
Layout file:
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="ratebutton"
android:text="#string/rate"
android:layout_gravity="center_horizontal" />
strings.xml:
<string name="rate">Rate with 5 stars please</string>

How can ImageView link to web page?

is it possible to make an imageview link to a web page such that when user taps on the image, it takes them to a web page?
Just add a click listener to the image to open an URL:
ImageView img = (ImageView)findViewById(R.id.foo_bar);
img.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse("http://casidiablo.net"));
startActivity(intent);
}
});
That's truly possible, at onClick handler you need to start an activity with intent specifying the uri. See How to open default browser for example.
another method we can even use is
image.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent redirect2=new Intent(getApplicationContext(),RedirectAct.class);
startActivity(redirect2);
}
});

Categories

Resources