请求出站通话权限以拨打紧急号码。

huangapple go评论113阅读模式
英文:

Requesting outgoing call permissions for emergency numbers

问题

I understand that you'd like a translation of the provided text. Here it is:

我想创建一个检查手机外拨电话并在紧急号码时调用我的广播接收器的安卓应用程序。我知道Google Play商店有一些限制和可能被列入黑名单的风险,但我需要先上传应用程序以签署他们的声明。

有一些类似的问题,我已经尝试了所有这些方法。我相信在过去几年里规则已经发生了相当大的变化。

问题:
我打算在我的广播接收器中接收安卓意图操作NEW_OUTGOING_CALL,但是我无法接收。我能够接收其他安卓操作,如AIRPLANE_MODE。但是由于某种原因,NEW_OUTGOING_CALLS在我的接收器中没有接收到(尝试过API 28-33)。我已经尝试了简单的提示消息和调试器断点,以查看是否触发了onReceive,但它只对AIRPLANE_MODE触发,而不对NEW_OUTGOING_CALL触发。

清单:

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

<receiver android:name=".ConnectionReceiver" android:enabled="true" android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.PHONE_STATE" />
    </intent-filter>
</receiver>

ConnectionReceiver.kt

class ConnectionReceiver : BroadcastReceiver() {
    override fun onReceive(context: Context, intent: Intent) {
        if (intent.action == "android.intent.action.NEW_OUTGOING_CALL") {
            //Toast.make.... <--- 这里只是一个测试用的提示消息
        }
    }
}

期望:
应该显示提示消息或触发断点

我需要添加其他权限吗(如MANAGE_OWN_CALLS)?或者在2023年这完全被禁止了吗?我在模拟器Nexus API 28和Pixel 4 API 33上尝试过。

英文:

I want to create an android application that checks outgoing calls and if it's an emergency number, my broadcast receiver is called. I'm aware of Google play store restrictions and the probability of being blacklisted. But I need to upload the application first to sign their declaration.

There are several similar questions and I have tried all of them. I believe the rules have changed considerably during the last few years.

Problem:
I intent to receive the android intent action NEW_OUTGOING_CALL in my broadcast receiver but I am unable to. I'm able to receive other android actions like AIRPLANE_MODE. But for some reason, NEW_OUTGOING_CALLS are not received in my receiver (Tried API 28-33). I've tried simple toast messages and debugger breakpoints to see if onReceive is triggered but it only triggers for AIRPLANE_MODE and not NEW_OUTGOING_CALL.

Manifest

&lt;uses-permission android:name=&quot;android.permission.PROCESS_OUTGOING_CALLS&quot;/&gt;
&lt;uses-permission android:name=&quot;android.permission.READ_PHONE_STATE&quot;/&gt;

&lt;receiver android:name=&quot;.ConnectionReceiver&quot; android:enabled=&quot;true&quot; android:exported=&quot;true&quot;&gt;
    &lt;intent-filter&gt;
        &lt;action android:name=&quot;android.intent.action.NEW_OUTGOING_CALL&quot; /&gt;
    &lt;/intent-filter&gt;
    &lt;intent-filter&gt;
        &lt;action android:name=&quot;android.intent.action.PHONE_STATE&quot; /&gt;
    &lt;/intent-filter&gt;
&lt;/receiver&gt;

ConnectionReceiver.kt

class ConnectionReceiver : BroadcastReceiver() {
    override fun onReceive(context: Context, intent: Intent) {
        if (intent.action == &quot;android.intent.action.NEW_OUTGOING_CALL&quot;) {
            //Toast.make.... &lt;--- Just a test toast here
        }
    }
}

Expectation:
The toast message should be shown or breakpoint must be hit

Do I need to add other permissions (like MANAGE_OWN_CALLS)? Or is this completely prohibited in 2023? Tried on emulator Nexus API 28, Pixel 4 API 33

答案1

得分: 0

以下是您提供的内容的中文翻译:

我创建了一个类似的应用程序,现在分享我的代码,希望能帮助你

广播接收器

public class OutgoingCallReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {

            TelephonyManager tm = (TelephonyManager)context.getSystemService(Service.TELEPHONY_SERVICE);
            if (tm.getCallState() == TelephonyManager.CALL_STATE_OFFHOOK) {

                String number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);

            }

    }

}

Manifest.xml

 <uses-permission android:name="android.permission.NEW_OUTGOING_CALL" />
    <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

在运行时请求权限

if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE)
                != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.PROCESS_OUTGOING_CALLS, Manifest.permission.READ_PHONE_STATE},
                    1);
        }

我这里没有紧急号码的功能,但是我在开发者博客上找到了一些信息

请注意,系统只为与核心拨号功能(如紧急号码)无关的号码广播 NEW_OUTGOING_CALL。这意味着 NEW_OUTGOING_CALL 无法干扰访问紧急服务,就像您使用 CALL_PRIVILEGED 可能会导致的那样。

https://android-developers.googleblog.com/2013/05/handling-phone-call-requests-right-way.html

英文:

I have made a similar application , I am sharing my code hope it helps you

BroadcastReceiver

public class OutgoingCallReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {

            TelephonyManager tm = (TelephonyManager)context.getSystemService(Service.TELEPHONY_SERVICE);
            if (tm.getCallState() == TelephonyManager.CALL_STATE_OFFHOOK) {

                String number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);

            }

    }

}

Manifest.xml

 &lt;uses-permission android:name=&quot;android.permission.NEW_OUTGOING_CALL&quot; /&gt;
    &lt;uses-permission android:name=&quot;android.permission.PROCESS_OUTGOING_CALLS&quot; /&gt;
    &lt;uses-permission android:name=&quot;android.permission.READ_PHONE_STATE&quot; /&gt;

Requesting permission at runtime

if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE)
                != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.PROCESS_OUTGOING_CALLS, Manifest.permission.READ_PHONE_STATE},
                    1);
        }

I do not have the have the emergency number functionality here
But researched and found something from the developers blog


> Note that the system broadcasts NEW_OUTGOING_CALL only for numbers that are not associated with core dialing capabilities such as emergency numbers. This means that NEW_OUTGOING_CALL can not interfere with access to emergency services the way your use of CALL_PRIVILEGED might.

https://android-developers.googleblog.com/2013/05/handling-phone-call-requests-right-way.html

huangapple
  • 本文由 发表于 2023年5月25日 18:53:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76331511.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定