在android中点击textview拨打电话

发布于 2024-12-22 05:13:09 字数 2788 浏览 0 评论 0原文

我有一个问题,当我单击也包含电话号码的文本视图时,我想拨打电话。但是,当我单击“文本”视图时,它返回一个错误:

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)

并且我不知道如何解决该问题,请建议我有关此问题的正确解决方案。

代码:

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);
        }
    });

我还在清单文件中获得了有关 CALL 的许可。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

如果没结果 2024-12-29 05:13:09

将此属性添加到 XML 布局文件中的 textview 组件,如下所示:

<TextView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:autoLink="phone"
    android:text="123 123 1234" />

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" />
这样的小城市 2024-12-29 05:13:09

这对我有用

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

This worked for me

  <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:autoLink="phone"
        android:background="#ADD8E6"
        android:text="555-468-0602" />
无风消散 2024-12-29 05:13:09

将其更改为:callIntent.setData(Uri.parse("tel:"+phone_no));

并且我没有添加此:callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

但它对我有用

Change it to :callIntent.setData(Uri.parse("tel:"+phone_no));

and i didnt add this: callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

but its working for me

多孤肩上扛 2024-12-29 05:13:09
 import android.app.Activity;
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;

     public class CustomCellActivity extends Activity {
          

     /** Called when the activity is first created. */
                     

      @Override
          

     public void onCreate(Bundle savedInstanceState) {
                            

     super.onCreate(savedInstanceState);
        

     setContentView(R.layout.main);


           Button Phone = (Button) findViewById(R.id.button1);
           

     Phone.setOnClickListener(new View.OnClickListener() {
       @Override
      

     public void onClick(View v) {
   

     Intent sIntent = new Intent(Intent.ACTION_CALL, Uri
     

     .parse("tel:12345"));
   

     sIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   
    

     startActivity(sIntent);
  

    }
  

    });

这段代码对我有用。自己尝试一下。

 import android.app.Activity;
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;

     public class CustomCellActivity extends Activity {
          

     /** Called when the activity is first created. */
                     

      @Override
          

     public void onCreate(Bundle savedInstanceState) {
                            

     super.onCreate(savedInstanceState);
        

     setContentView(R.layout.main);


           Button Phone = (Button) findViewById(R.id.button1);
           

     Phone.setOnClickListener(new View.OnClickListener() {
       @Override
      

     public void onClick(View v) {
   

     Intent sIntent = new Intent(Intent.ACTION_CALL, Uri
     

     .parse("tel:12345"));
   

     sIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   
    

     startActivity(sIntent);
  

    }
  

    });

This code works for me. try it urself.

落花浅忆 2024-12-29 05:13:09

在AndroidManifest.xml文件中添加调用权限。

<uses-permission android:name="android.permission.CALL_PHONE"/>

在您的layout.xml 文件的文本视图中

<TextView
        android:clickable="true"
        android:autoLink="phone"
        ...
        ...
        .../>

在您的活动类中。添加了运行时权限检查。

if (Build.VERSION.SDK_INT > 22) {

            if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {

                ActivityCompat.requestPermissions(MoreProgramDetailActivity.this, new String[]{Manifest.permission.CALL_PHONE}, 101);

                return;
            }
            Intent callIntent = new Intent(Intent.ACTION_CALL);
            callIntent.setData(Uri.parse("tel:+" + phoneTV.getText().toString().trim()));
            startActivity(callIntent);
 } else {

            Intent callIntent = new Intent(Intent.ACTION_CALL);
            callIntent.setData(Uri.parse("tel:+" + phoneTV.getText().toString().trim()));
            startActivity(callIntent);
 }

Add permission to call in AndroidManifest.xml file.

<uses-permission android:name="android.permission.CALL_PHONE"/>

In your textview of your layout.xml file

<TextView
        android:clickable="true"
        android:autoLink="phone"
        ...
        ...
        .../>

In your activity class. Run-time permission check added.

if (Build.VERSION.SDK_INT > 22) {

            if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {

                ActivityCompat.requestPermissions(MoreProgramDetailActivity.this, new String[]{Manifest.permission.CALL_PHONE}, 101);

                return;
            }
            Intent callIntent = new Intent(Intent.ACTION_CALL);
            callIntent.setData(Uri.parse("tel:+" + phoneTV.getText().toString().trim()));
            startActivity(callIntent);
 } else {

            Intent callIntent = new Intent(Intent.ACTION_CALL);
            callIntent.setData(Uri.parse("tel:+" + phoneTV.getText().toString().trim()));
            startActivity(callIntent);
 }
§普罗旺斯的薰衣草 2024-12-29 05:13:09
      TextVIew dialers=(TextView)this.findViewById(R.id.dialer);
      dialers.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View view) 
        {
                        launchDialer(dialers.getText().toString());
                    }

       });
      TextVIew dialers=(TextView)this.findViewById(R.id.dialer);
      dialers.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View view) 
        {
                        launchDialer(dialers.getText().toString());
                    }

       });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文