【问题标题】:How to open number dialer pad programmatically in android?如何在android中以编程方式打开数字拨号盘?
【发布时间】:2012-10-29 20:11:00
【问题描述】:

我想在 android 中以编程方式显示数字拨号键盘(电话呼叫)。代码可用于直接号码拨号,但我只需要在单击按钮时显示拨号键盘。

【问题讨论】:

    标签: android buttonclick phone-call numeric-keypad


    【解决方案1】:

    如果您想在不插入任何号码的情况下以编程方式打开拨号器,则可以使用此代码:

    Java

    Intent intent = new Intent(Intent.ACTION_DIAL);
    startActivity(intent);
    

    科特林

    val intent = Intent(Intent.ACTION_DIAL)
    startActivity(intent)
    

    如果您需要打开已输入号码的拨号器,您可以使用此代码:

    Java

    Intent intent = new Intent(Intent.ACTION_DIAL);
    intent.setData(Uri.parse("tel:123 456789"));
    startActivity(intent);
    

    科特林

    val intent = Intent(Intent.ACTION_DIAL)
    intent.data = Uri.parse("tel:123 456789")
    startActivity(intent)
    

    【讨论】:

      【解决方案2】:

      这是不同的,但如果你想通过点击一个数字来访问你的拨号盘,请在你的 xml 中声明自动链接属性

      android:autoLink="phone"
      

      【讨论】:

        【解决方案3】:

        如果你想在非活动类中使用它,那么创建一个这样的函数:

        package bp;
        
        import android.app.Activity;
        import android.content.Intent;
        import android.net.Uri;
        
        import session.MyApplication;
        
        /**
         * Created by Atiar Talukdar on 7/11/2019.
         */
        public class Utils {
        
            public static void openDialPad(Activity activity, String phoneNumber) {
                Intent intent = new Intent(Intent.ACTION_DIAL);
                intent.setData(Uri.parse("tel:" + phoneNumber));
                activity.startActivity(intent);
            }
        }
        

        然后从任何地方调用:

        Utils.openDialPad(getActivity(),data.getContactNo());

        Utils.openDialPad(this,data.getContactNo());

        【讨论】:

          【解决方案4】:
          Intent intent =  new Intent(Intent.ACTION_CALL_BUTTON);
          startActivity(intent);
          

          它将显示拨号窗口检查here 以获取信息

          【讨论】:

            【解决方案5】:
             public void openDialPad(String phoneNumber) {
                    Intent intent = new Intent(Intent.ACTION_DIAL);
                    intent.setData(Uri.parse(phoneNumber));
                    startActivity(intent);
                }
            

            【讨论】:

              【解决方案6】:

              制作按钮或任何小部件示例:button1

                button1.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View v) {
                          Intent callIntent = new Intent(Intent.ACTION_DIAL);
                          callIntent.setData(Uri.parse("tel:"+button1.getText().toString().trim()));
                          startActivity(callIntent);
              
                      }
                  });
              

              在清单中添加权限:

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

              【讨论】:

                【解决方案7】:
                Intent callIntent = new Intent(Intent.ACTION_DIAL);
                callIntent.setData(Uri.parse("tel:" + phoneNumber));
                 if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                                // TODO: Consider calling
                                //    ActivityCompat#requestPermissions
                                // here to request the missing permissions, and then overriding
                                //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
                                //                                          int[] grantResults)
                                // to handle the case where the user grants the permission. See the documentation
                                // for ActivityCompat#requestPermissions for more details.
                                return;
                            }
                startActivity(callIntent);
                

                此外,您应该在清单中按如下方式注册自定义拨号屏幕:

                <application
                android:icon="@drawable/ic_launcher"
                android:label="@string/app_name" >
                <activity
                    android:name=".MyDialerApplication"
                    android:label="@string/app_name" >
                
                    <intent-filter android:priority="100" >
                        <action android:name="android.intent.action.MAIN" />
                         <action android:name="android.intent.action.DIAL" />
                         <action android:name="android.intent.action.CALL_PRIVILEGED" />
                        <category android:name="android.intent.category.DEFAULT" />
                        <data android:scheme="tel" />
                
                    </intent-filter>
                </activity>
                

                【讨论】:

                  【解决方案8】:
                  Intent intent = new Intent(Intent.ACTION_DIAL);
                  intent.setData(Uri.parse("tel:9999999999"));
                  startActivity(intent); 
                  

                  为此,我们不需要在 AndroidManifest.xml

                  中添加任何权限

                  【讨论】:

                  • 对于 ACTION_DIAL,我们不需要 CALL_PHONE 权限。它只需要 ACTION_CALL
                  猜你喜欢
                  • 2014-10-04
                  • 2011-03-11
                  • 1970-01-01
                  • 2021-11-28
                  • 1970-01-01
                  • 2017-02-22
                  • 1970-01-01
                  • 2020-02-23
                  • 1970-01-01
                  相关资源
                  最近更新 更多