在android中从应用程序内调用电话的正确方法

发布于 2024-10-10 19:38:50 字数 772 浏览 11 评论 0原文

我有一小段代码,基本上应该在按下按钮时拨打电话。我在网上查了一下,所有的来源基本上都给出了相同的代码。但由于某种原因,这段代码不起作用。它使应用程序崩溃,但 LogCat 不显示任何内容(意味着日志完全空白)。我还应该提到,在我的清单文件中,我确实添加了以下权限

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

我的代码如下。任何帮助将不胜感激!

phoneButton.setOnClickListener(new OnClickListener () {
            public void onClick(View v) {
                try {
                final Intent callIntent = new Intent(Intent.ACTION_CALL);
                callIntent.setData(Uri.parse("tel:232131232"));
                ContactUs.this.startActivity(callIntent);
                }catch (ActivityNotFoundException e){
                    Log.e("Dialing", "call Failed!", e);

                }
            }           
        });

I have a small piece of code which is basically supposed to make a phone call when a button is pushed. I looked it up online and all the sources basically gave the same code. But for some reason this code doesn't work. It makes the app crash but the LogCat doesn't display anything (meaning the log is completely blank). I should also mention that in my manifest file I did add the following permission

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

The code I have is as follows. Any help would be greatly appreciated!

phoneButton.setOnClickListener(new OnClickListener () {
            public void onClick(View v) {
                try {
                final Intent callIntent = new Intent(Intent.ACTION_CALL);
                callIntent.setData(Uri.parse("tel:232131232"));
                ContactUs.this.startActivity(callIntent);
                }catch (ActivityNotFoundException e){
                    Log.e("Dialing", "call Failed!", e);

                }
            }           
        });

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

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

发布评论

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

评论(3

江湖正好 2024-10-17 19:38:50

你第二次把 android 拼写错了...

You spelt android wrong the second time...

凉风有信 2024-10-17 19:38:50

听起来您需要添加拨打电话的用户权限。 权限为:

我相信清单文件中的

Sounds like you need to add the user-permission for making a phone call. I believe the permission is:

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

in your manifest file.

世态炎凉 2024-10-17 19:38:50

这是我目前正在 HTC Desire 上测试的 Activity 类的片段 -

okButton.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View v) {
       Intent intent = new Intent(Intent.ACTION_CALL);
       intent.setData(Uri.parse("tel:" + getPhoneNumber()));
       startActivity(intent);
   }
});

我建议将 ContactUs.this.startActivity(callIntent); 更改为 startActivity(callIntent); 并且再次测试一下。

This is a snippet from an Activity class I am currently testing on my HTC Desire -

okButton.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View v) {
       Intent intent = new Intent(Intent.ACTION_CALL);
       intent.setData(Uri.parse("tel:" + getPhoneNumber()));
       startActivity(intent);
   }
});

I suggest changing ContactUs.this.startActivity(callIntent); to startActivity(callIntent); and testing it again.

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