Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dialing a phone call on click of textview in android

Tags:

I have a question that I want to dial a phone call when I click on a text view which also contain a phone number. But when I click on a Text view it returns an error as:

12-22 10:32:36.703: ERROR/AndroidRuntime(399): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL dat=4564646546 flg=0x10000000 } 12-22 10:32:36.703: ERROR/AndroidRuntime(399):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408) 12-22 10:32:36.703: ERROR/AndroidRuntime(399):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378) 12-22 10:32:36.703: ERROR/AndroidRuntime(399):     at android.app.Activity.startActivityFromChild(Activity.java:3057) 12-22 10:32:36.703: ERROR/AndroidRuntime(399):     at android.app.Activity.startActivityForResult(Activity.java:2837) 12-22 10:32:36.703: ERROR/AndroidRuntime(399):     at android.app.Activity.startActivity(Activity.java:2923) 12-22 10:32:36.703: ERROR/AndroidRuntime(399):     at com.shipface.profile.Profile$1.onClick(Profile.java:66) 12-22 10:32:36.703: ERROR/AndroidRuntime(399):     at android.view.View.performClick(View.java:2408) 12-22 10:32:36.703: ERROR/AndroidRuntime(399):     at android.view.View$PerformClick.run(View.java:8816) 12-22 10:32:36.703: ERROR/AndroidRuntime(399):     at android.os.Handler.handleCallback(Handler.java:587) 12-22 10:32:36.703: ERROR/AndroidRuntime(399):     at android.os.Handler.dispatchMessage(Handler.java:92) 12-22 10:32:36.703: ERROR/AndroidRuntime(399):     at android.os.Looper.loop(Looper.java:123) 12-22 10:32:36.703: ERROR/AndroidRuntime(399):     at android.app.ActivityThread.main(ActivityThread.java:4627) 12-22 10:32:36.703: ERROR/AndroidRuntime(399):     at java.lang.reflect.Method.invokeNative(Native Method) 12-22 10:32:36.703: ERROR/AndroidRuntime(399):     at java.lang.reflect.Method.invoke(Method.java:521) 12-22 10:32:36.703: ERROR/AndroidRuntime(399):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 12-22 10:32:36.703: ERROR/AndroidRuntime(399):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 12-22 10:32:36.703: ERROR/AndroidRuntime(399):     at dalvik.system.NativeStart.main(Native Method) 

and I don't know how to resolve the same, please suggest me the right solution regarding this.

Code:

tv_phone.setOnClickListener(new View.OnClickListener() {          @Override         public void onClick(View arg0) {             // TODO Auto-generated method stub             String phone_no= tv_phone.getText().toString().replaceAll("-", "");             Intent callIntent = new Intent(Intent.ACTION_CALL);             callIntent.setData(Uri.parse(phone_no));             callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);              startActivity(callIntent);         }     }); 

I also take a permission regarding CALL in our Manifest file.

like image 955
Sanat Pandey Avatar asked Dec 22 '11 05:12

Sanat Pandey


People also ask

Can TextView have onClick android?

as you're telling in your xml to capture the click for the text view ( android:onClick="onClick" ) in onClick module, you don't need to add an onClick listener in your java code. Show activity on this post. Show activity on this post.


2 Answers

Add this attribute to your textview component within the XML layout file like this:

<TextView      android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:autoLink="phone"     android:text="123 123 1234" /> 
like image 149
Nart Barileva Avatar answered Sep 29 '22 19:09

Nart Barileva


this work for me :)

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:autoLink="phone" android:background="#ADD8E6" android:text="555-468-0602" />

like image 24
AndreS Avatar answered Sep 29 '22 20:09

AndreS