Detect a number phone in the email body and call it

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Detect a number phone in the email body and call it

Postby aminaz » Mon Jan 11, 2010 3:20 pm

I try to find a tutorial in your forum but i didn't find nothing so please help:
i want to develop an android application which search a phone number in the email body and make it like a link when i clic on i make a call ...
So I try to begin with a simple view which can make calls...and i need your help
Thank you
aminaz
Junior Developer
Junior Developer
 
Posts: 19
Joined: Thu Jan 07, 2010 5:07 pm

Top

Postby Draffodx » Mon Jan 11, 2010 3:23 pm

look into the action_call and action_dial intents to start with
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Postby jwei512 » Tue Jan 12, 2010 7:19 am

@ Draffodx - I don't think you're getting at the meat of his problem

Eventually you'll need to use the ACTION_DIAL intents, but that's much later, the issue at hand is finding phone numbers given a string of text.

To do that you're going to have to use REGEX (regular expressions) to parse the email body.

You want to look into Java's Pattern/Matcher classes:

http://java.sun.com/j2se/1.4.2/docs/api ... ttern.html
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
Senior Developer
Senior Developer
 
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Postby Draffodx » Tue Jan 12, 2010 10:50 am

jwei512 wrote:@ Draffodx - I don't think you're getting at the meat of his problem


Sorry, I got it wrong indeed! :oops:
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Postby Droid123 » Tue Jan 12, 2010 12:08 pm

How about you Linkify the emailbody TextView?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. TextView linker = (TextView)findViewById(R.id.textbox);
  2.  
  3. linker.setText(emailbodytext);
  4.  
  5. Linkify.addLinks(linker, Linkify.PHONE_NUMBERS);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
Droid123
Experienced Developer
Experienced Developer
 
Posts: 77
Joined: Sat Nov 21, 2009 1:21 pm

SetOnlongClick

Postby aminaz » Tue Jan 12, 2010 6:42 pm

Thnks for replaying .
My Application has succeeded and everything is ok but i want when i clic for a long time in the phone number a frame appear in order to save the number so i put an OnLongClickListener method taht i define like this:
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
for ( URLSpan urlSpan : urlSpans )
{
Intent dial_intent = new Intent(main2.this,contactsave.class);
startActivity(dial_intent);
}
return true;
}

but it didn't work so please give me a hand
THANKS
aminaz
Junior Developer
Junior Developer
 
Posts: 19
Joined: Thu Jan 07, 2010 5:07 pm

Top

Postby jwei512 » Tue Jan 12, 2010 8:03 pm

What exactly didn't work and what is this contactsave.class? Aren't you trying to dial a number?
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
Senior Developer
Senior Developer
 
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Postby aminaz » Wed Jan 13, 2010 9:53 am

Good Morning
yes i'm and i did it (i call the number) but i want to save it in my contacts list so i want to Long clic on the number phone (it appears like a link) and a context menu appear that ask me to save or not.
contactsave.class is the classe that show me this context menu.
i have also a question: did context menu need an adapter ????

Thnks
aminaz
Junior Developer
Junior Developer
 
Posts: 19
Joined: Thu Jan 07, 2010 5:07 pm

Postby jwei512 » Wed Jan 13, 2010 10:43 am

I don't believe the context menu NEEDS an adapter - although it is typically used in conjunction with a ListView and not like the way you are implementing it. Is there any reason why you need to long click it? Why can't you just have an onClickListener attached to each link that brings up some sort of dialog? I feel like that implementation would be much more simple and effective...
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
Senior Developer
Senior Developer
 
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Postby aminaz » Thu Jan 14, 2010 12:45 pm

Thnks i make a ContextMenu and every thing is ok but i want to save the number that i clicked on because i need it in order to call it or to add it as a contact or to send him a sms

look this is my code


public boolean onContextItemSelected(MenuItem aItem) {
AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) aItem.getMenuInfo();
//NUMBER=txtbody.getUrls().

/* Switch on the ID of the item, to get what the user selected. */
switch (aItem.getItemId()) {

case CONTEXTMENU_CALL:
/* Get the selected item out of the Adapter by its position. */

Intent intent1 = new Intent(Intent.ACTION_DIAL);
//intent1.getData();
startActivity(intent1);
break;

case CONTEXTMENU_INSEERTPHONE:

Intent intent2 = new Intent(Intent.ACTION_INSERT_OR_EDIT);
intent2.setType(Contacts.People.CONTENT_ITEM_TYPE);
intent2.putExtra(Insert.PHONE, Uri.parse("tel:" + NUMBER));
startActivity(intent2);
break;



case CONTEXTMENU_SENDSMS:
Intent intent4 = new Intent(Intent.ACTION_VIEW);
intent4.putExtra("address", NUMBER);
intent4.setType("vnd.android-dir/mms-sms");
startActivity(intent4);
break;


}
return false;

}


i need to save the number so i did like this //NUMBER=txtbody.getUrls().ToString();
but i don't get it :(((
Please help
Thnks
aminaz
Junior Developer
Junior Developer
 
Posts: 19
Joined: Thu Jan 07, 2010 5:07 pm

Postby aminaz » Fri Jan 15, 2010 7:31 am

Good mornning i know that i asked so musch but please answer my question i need your help please please
aminaz
Junior Developer
Junior Developer
 
Posts: 19
Joined: Thu Jan 07, 2010 5:07 pm

Postby jwei512 » Fri Jan 15, 2010 7:39 am

What exactly is txtBody? Is it a String? Or some object you created? And what does the method getURLs do?
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
Senior Developer
Senior Developer
 
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Postby aminaz » Fri Jan 15, 2010 12:50 pm

So
TextBody is a TEXTVIEW and also the text of the mail that contains the number of the phone
GetURLS get all URLS in this TEXTVIEW
it returns a type that i try to convert it toString this is all what i know :$
look to this code :

TextView tv = ( TextView ) findViewById( R.id.link );
WebView wv = ( WebView ) findViewById( R.id.webView );
URLSpan[] urlSpans = tv.getUrls();
for ( URLSpan urlSpan : urlSpans )
{
wv.loadUrl( urlSpan.getURL() );
}

i found it in the net
http://www.coderanch.com/t/435124/Andro ... w-autoLink


Thnks
aminaz
Junior Developer
Junior Developer
 
Posts: 19
Joined: Thu Jan 07, 2010 5:07 pm

Postby jwei512 » Sat Jan 16, 2010 2:01 am

Hm... well it seems like your code should be something like:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. URLSpan[] numbers =txtbody.getUrls();
  3.  
  4. for(URLSpan number : numbers) {
  5.  
  6.      intent2.putExtra(Insert.PHONE, Uri.parse("tel:" + number.getURL()));
  7.  
  8. }
  9.  
  10.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


Just looking through the docs it seems like that's how you're supposed to use this getUrls() method and how to use the URLSpan class.

Let me know if this helps.
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
Senior Developer
Senior Developer
 
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Postby aminaz » Sat Jan 16, 2010 11:44 am

Yeeeeeeeeeeeeeeeeeeeeeeeeeeeees
It work like a charme THnk uuuuuuuuuuuuuuuuuuuuuuu
see
case CONTEXTMENU_INSEERTPHONE:
URLSpan[] numbers2 =txtbody.getUrls();
for(URLSpan number2 : numbers2) {
Intent intent2 = new Intent(Intent.ACTION_INSERT_OR_EDIT);
intent2.setType(Contacts.People.CONTENT_ITEM_TYPE);
intent2.putExtra(Insert.PHONE,number2.getURL());

startActivity(intent2);
}

break; // it put a number that i don't know it !!!! :(

// in order to insert a new contact in my appliaction
case CONTEXTMENU_INSEERTMYAPPLICATION:
URLSpan[] numbers3 =txtbody.getUrls();
for(URLSpan number3 : numbers3) {
Intent intent3 = new Intent(view_mail1.this, new_contact1.class);
intent3.putExtra(Insert.PHONE,Uri.parse("tel:" + number3.getURL()));

startActivity(intent3);
}

break;
// no number in the textview phone of my application i need to know how to initialisate a class and insert what i need to it

case CONTEXTMENU_SENDSMS:

URLSpan[] numbers4 =txtbody.getUrls();
for(URLSpan number4 : numbers4) {
Intent intent4 = new Intent(Intent.ACTION_VIEW);

intent4.setType("vnd.android-dir/mms-sms");
intent4.putExtra("address", number4.getURL());
// when i put intent4.putExtra("address", "221400"); it works
startActivity(intent4);
}
break;


But none of this work , i see the views but the number is not not inserted
new_contact1 is classe containt a many textview in witch we can insert the phone number so i have a textview in this class


Tnks for all
aminaz
Junior Developer
Junior Developer
 
Posts: 19
Joined: Thu Jan 07, 2010 5:07 pm

Top
Next

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 7 guests