【问题标题】:Adding direct dial shortcuts to my app向我的应用程序添加直拨快捷方式
【发布时间】:2010-08-05 00:35:30
【问题描述】:

我正在制作一个可以启动其他应用的应用。我已经使用 Spinners 很好地启动了应用程序,但是,我还想让用户能够从它启动直接拨号。

现在我已经有了用户可以配置的“热键”按钮。目前,当用户想要配置其中一个“热键”时,我使用微调器让他们从手机上所有已安装的应用程序中进行选择。对于初学者,我希望他们能够在微调器中查看已安装的应用程序和快捷方式,以便他们可以将直接拨号映射到这些“热键”之一。

所以我的主要问题是,如何查找所有可用的已定义快捷方式并执行它们,以及如何在我的应用程序中创建自己的直接拨号?

【问题讨论】:

    标签: android android-intent shortcut


    【解决方案1】:

    直接拨打电话

    startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + NUMBER)));
    

    【讨论】:

      【解决方案2】:

      这是一个简单的函数

      public static void go2Call(Context context, String phoneNo) {
      
          Intent intent = null;
          Uri destUri = null;
          /*
           * http://developer.android.com/guide/appendix/g-app-intents.html
              <uses-permission id="android.permission.CALL_PHONE" />
              tel: phone_number
           */
      
          if(DEBUG)Log.d(TAG, "go2Call ->" + "phoneNo:"+phoneNo);
          phoneNo = PhoneNumberUtils.convertKeypadLettersToDigits(phoneNo);
          if(DEBUG)Log.d(TAG, "go2Call ->" + "phoneNo(normalized):"+phoneNo);
      
      
          if ( !TextUtils.isEmpty(phoneNo) ) {
      
              destUri = Uri.parse("tel:" + phoneNo);
          }
      
          if (destUri!=null) {
              intent = new Intent( Intent.ACTION_VIEW, destUri );
          }
      
              if ( intent!=null && isIntentAvailable(context, intent) ) {
                  context.startActivity(intent);
              }
              else {
                  // TODO: display error msg
                  Log.w(TAG, "error pr intent not available! ->" + "phoneNo:"+phoneNo);
              }
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-03-26
        • 1970-01-01
        • 2011-10-10
        • 1970-01-01
        • 2011-07-04
        • 2017-06-09
        • 1970-01-01
        相关资源
        最近更新 更多