Android 没有找到处理意图 act​​ion.dial 的活动

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20531973/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 02:59:16  来源:igfitidea点击:

No activity found to handle intent action.dial

androidandroid-intentandroid-permissionsphone-numberphone-call

提问by Sluggo

I'm trying to make my app call a number from an EditText, but I get:

我试图让我的应用从 EditText 调用一个号码,但我得到:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.DIAL dat=Ring Tel nr. 123456789 }

I've searched a while for an answer, but most of the answes are permissions and add activity to the Manifest. I've done both, if I'm not doing it wrong. And I'm running it on my phone, not the emulator. I've tried both with and without the intent-filters. Here are the codes: Manifest: <uses-permission android:maxSdkVersion="19" android:name="android.permission.CALL_PHONE"/>

我已经搜索了一段时间来寻找答案,但大多数答案都是权限并将活动添加到清单中。如果我没有做错的话,我已经完成了这两项工作。我在手机上运行它,而不是模拟器。我已经尝试过使用和不使用意图过滤器。以下是代码: 清单:<uses-permission android:maxSdkVersion="19" android:name="android.permission.CALL_PHONE"/>

        <activity
        android:name="nu.sluggo.testapp.annons.Activity2">
        <intent-filter>
    <action android:name="android.intent.action.DIAL" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

Button to make the call (gets phone number from SharedPrefs to a1 below:)

拨打电话的按钮(从 SharedPrefs 获取电话号码到下面的 a1 :)

        knapp_ring.setOnClickListener(new View.OnClickListener() {
        Intent call = new Intent(Intent.ACTION_DIAL);
        @Override
        public void onClick(View v){
            call.setData(Uri.parse("Telnr:" + a1));
            startActivity(call);
        }
    });

回答by CommonsWare

Ring Tel nr. 123456789is not a valid phone number, and that is what is in your Intent. "Telnr:" + a1also would not appear to be valid. Use tel:followed by the phone number as the value passed to Uri.parse():

Ring Tel nr. 123456789不是有效的电话号码,这就是您的Intent. "Telnr:" + a1也似乎无效。使用tel:后跟电话号码作为传递给 的值Uri.parse()

 Uri.parse("tel:" + a1)