Make call on number click - android

I need a little help.
I have ,in my app, a textView which contains a phone number,and i want to make a call when i click that phone number.
I've already accomplished that:
sitePhone.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
String number = "tel:" + sitePhone.getText().toString().trim();
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(number));
startActivity(callIntent);
}
});
Now the problem is that sometimes i have on my text view 2 or 3 phone numbers.Something like this: "07456443345 FAR: 0745456334".I take the phone number string from the database so it cannot be altered.
Any ides of how i can make a call on each number click? thanks in advance

i found a simple answer:
android:autoLink="phone" will to the trick.

Related

How to implement short press & long press(or long hold) in android app effectively?

I am creating an android application wherein I have mentioned the phone number, email, website of the business similar to the screenshot of google maps as attached.
Just like in the g maps where
Single click makes an intent to the respective app (opens dialer with phone number copied) etc.
Long Click/Press & hold will copy the number to clipboard displaying a toast that "Phone number is copied to clicpboard".
Now I have set up the intents properly and they are working fine --> step-1 achieved.
When I try to display the toast using "OnLongClickListener" method it is taking quite some time to display the toast message. Is there any way we can speed this up or am I missing something or should I use some other alternative like onTouch() method?
(Stuck with this, yet to learn and try out copying to clipboard thing. Inputs in this regards are also welcome!)
In the g maps app, the toast message appears almost instantly on press & hold. So the same is to be achieved.
The code extract from MainActivity.java (The website, phone number, email id are text views with drawableLeft. And I found out that we cannot use setOnItemLongClick on TextView as it is only for ListView)
// This method is called when the website text view is clicked and opens the compnay website
public void openWebsite(View v) {
TextView textView = (TextView) findViewById(R.id.webURL_text_view);
textView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent openWebsiteIntent = new Intent(Intent.ACTION_VIEW);
openWebsiteIntent.setData(Uri.parse("https://www.company.com"));
if (openWebsiteIntent.resolveActivity(getPackageManager()) != null) {
startActivity(openWebsiteIntent);
}
}
});
textView.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View view) {
showMessage();
return true;
}
});
}
public void showMessage(){
Toast.makeText(this,"Information copied to Clipboard", Toast.LENGTH_LONG).show();
}
I am new to android development and just trying out something, so please be as elaborative as possible. Thank You.

Check if is it empty on edit text is not working

What i have is android app , and in one of activities i have two edit text with button, and i want either if one of them were empty when i click the button to preform a toast to tell the user to enter data, and if it was not empty i want it to open intent and do other thing , here is my code :
add.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(quantity.getText()==null){
Toast.makeText(FullImageActivity2.this,"please enter quantity",Toast.LENGTH_LONG).show();
}
else if(extra.getText()==null){
Toast.makeText(FullImageActivity2.this,"please enter extra",Toast.LENGTH_LONG).show();
}
else{
Quan=quantity.getText().toString();
name=itemId;
image=R.drawable.products;
Intent cart=new Intent(FullImageActivity2.this,CartList.class);
cart.putExtra("name", name);
cart.putExtra("quantity",Quan);
cart.putExtra("image", image);
Log.e("quan",Quan+"");
Log.e("name",name+"");
startActivity(cart);
}
}
});
But the weird thing that if they were empty , else is working !! which is not logic at all .. the validation on empty text is not empty , Why this is happening?? Help plz
Try to used .equals() method
if(quantity.getText().toString().trim().equals(""))
Try
if(editText.getText().toString().length()<1){
//do something
}
And of course you are mistaking null with "" which means no string but not null.
When Edittext is empty, getText() method returns empty string, not null.
Try:
if(quantity.getText().toString().equals("")){
Of course, if you want to avoid entering only spaces, use
if(quantity.getText().toString().trim().equals("")){

Make phone call without getting phone number (click icon to call) in android?

I'm currently working on my 2nd program and stuck with phone calling, sending SMS, emailing, and showing location using Google Map. I'm using ImageButtons for all of these. User doesn't need to type any numbers or addresses (not using EditText to get user input). However, it doesn't work.
For example, when user click on Phone icon, it will make a call. However, I still need a user input (the actual message, not the destination number or email address) for sending SMS and email. I can do it if I use EditText. However, without using EditText, I cannot do it. How do I do this? I've added users permission in manifest file.
PhoneActivity .java
public class PhoneActivity extends Activity {
ImageButton btnphonecall;
String phoneNumber = "091111111";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_phone);
btnphonecall=(ImageButton)findViewById(R.id.imageButton1);
btnphonecall.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(Intent.ACTION_CALL);
i.setData(Uri.parse("091111111"));
PhoneActivity.this.startActivity(i);
//I've tried startActivity(i) along but still doesn't work
}
});
}
Use this:
Uri number = Uri.parse("tel:"+091111111 );
Intent dial = new Intent(Intent.ACTION_CALL,
number);
dial.setPackage("com.android.phone");
PhoneActivity.this.startActivity(dial);
Try this:
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+phoneNumber));
startActivity(callIntent);

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: 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!
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.

Categories

Resources