【问题标题】:Android dialer applicationAndroid 拨号器应用程序
【发布时间】:2011-02-17 12:56:20
【问题描述】:

我正在想办法从我的自定义拨号器应用程序中替换默认拨号器应用程序,但我不知道如何实现这一点。

这就是我想要的

  • 创建自定义拨号器 UI
  • 只要按下呼叫按钮硬件或 Android 中的硬件,就会调用我的应用程序
  • 也可以从联系人屏幕调用应用程序

我指的是public static final String ACTION_DIAL

【问题讨论】:

标签: android phone-call


【解决方案1】:
  1. 创建一个简单的 Android 应用程序(我们的拨号器)。要真正打电话给某人,你只需要那个方法:

    private void performDial(String numberString) {
        if (!numberString.equals("")) {
           Uri number = Uri.parse("tel:" + numberString);
           Intent dial = new Intent(Intent.ACTION_CALL, number);
           startActivity(dial);
        }
    }
    
  2. 授予您的应用程序在 AndroidManifest 中调用的权限

    <uses-permission android:name="android.permission.CALL_PHONE" />
    
  3. 在 AndroidManifest 中设置意图,告诉您的手机在需要拨号器时使用您的应用

当有人按下通话键时:

    <intent-filter>
        <action android:name="android.intent.action.CALL_BUTTON" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>

当有人触发 URI 时:

    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <action android:name="android.intent.action.DIAL" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="tel" />
    </intent-filter>

【讨论】:

  • 您好,感谢您的回复,它真的很棒,我得到了我想要的,但是我的应用程序只有在我使用硬件呼叫按钮时才会打开,但是如果我使用 android 软键来拨打电话它就不起作用
  • 如果您的手机 ui(即 htc sense)启动自己的拨号程序而不是启动拨号程序活动,那么您真的无能为力...
  • 感谢我第一次使用拨号器时的一件事
  • 你不能。至少据我所知。
  • 如果您看到联系人应用程序代码,您将看到使用了 android.intent.action.CALL_PRIVILEGED。另请参阅stackoverflow.com/questions/4293864/…
【解决方案2】:

这对我有用:

        <activity
        android:name=".activities.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <!-- open activity when establishing a call -->
        <intent-filter>
            <action android:name="android.intent.action.CALL_PRIVILEGED" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="tel" />
        </intent-filter>

    </activity>

【讨论】:

  • 正如我在另一个答案下评论的那样,这对我有用。不过,我认为 Google 在最近的一篇博文中不鼓励使用这种意图很奇怪:android-developers.blogspot.com/2013/05/…。如果我按照他们的建议使用 NEW_OUTGOING_CALL,我的应用程序不会与其他应用程序(例如 Skype)一起显示,作为从联系人应用程序拨打电话时的呼叫选项。此外,他们声称 CALL_PRIVILEGED 仅适用于系统应用程序。
【解决方案3】:

ACTION_DIAL 意图似乎允许您将一个号码传递给标准拨号器,以便用户拨打它,如果他们愿意的话,这不是您需要的。

您是否有具体问题,或者您是否正在寻找某人来告诉您如何实现您的应用在按下软件/硬件调用按钮时被调用?

看起来你需要 ACTION_CALL_BUTTON - http://developer.android.com/reference/android/content/Intent.html#ACTION_CALL_BUTTON

【讨论】:

  • 是的,我想要的只是创建一个自定义拨号器,我只使用了 android.intent.action.CALL_BUTTON 但它对我不起作用
  • Saurabh,你能解决这个问题吗?分享解决方案,让社区受益。
  • @ingsaurabh:如果您找到解决方案,请分享答案。
  • 我能够在本机拨号器应用程序之上叠加一个视图。更多信息请参阅:stackoverflow.com/questions/23701879/…
【解决方案4】:

参考this answerarekolek

这是第三方应用扩展InCallService的正确方式,在用户接受启动提示后,将替换系统默认的拨号器和InCallScreen。

他还在 Kotlin 中提供了 working sample app(奖励积分)。

请在那里为他的回答投票,我的工作不值得称赞。

注意:仅适用于 API 23+,可能需要extra permissions in API 26

【讨论】:

    猜你喜欢
    • 2014-04-14
    • 2012-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多