CTA-敏感行为-拨打电话

本文介绍了Android中实现拨打电话功能所需的权限设置及接口使用方法,包括`CALL_PHONE`和`MANAGE_OWN_CALLS`权限说明,以及`TelephonyManager`和`TelecomManager`接口的调用方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1 需求

  • 权限
    • android.permission.CALL_PHONE
    • android.permission.MANAGE_OWN_CALLS
  • 接口
    • android.telephony.TelephonyManager.call
    • android.telecom.TelecomManager.placeCall
  • action
    • android.intent.action.CALL
    • android.intent.action.DIAL

2 权限

android.permission.CALL_PHONE

  • Added in API level 1
  • Protection level: dangerous

Manifest.permission  |  Android Developers

http://androidxref.com/8.0.0_r4/xref/frameworks/base/core/res/AndroidManifest.xml


android.permission.MANAGE_OWN_CALLS

  • Added in API level 26
  • Protection level: normal

Manifest.permission  |  Android Developers

http://androidxref.com/8.0.0_r4/xref/frameworks/base/core/res/AndroidManifest.xml


3 接口

android.telephony.TelephonyManager.call

TelephonyManager  |  Android Developers

/frameworks/base/telephony/java/android/telephony/TelephonyManager.java


android.telecom.TelecomManager.placeCall

  • Added in API level 23
  • Manifest.permission.CALL_PHONE or Manifest.permission.MANAGE_OWN_CALLS

TelecomManager  |  Android Developers

/frameworks/base/telecomm/java/android/telecom/TelecomManager.java


4 示例

package com.example.call;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private static final String TAG = "MainActivity";

    EditText editTextPhoneNumber;

    String number;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        editTextPhoneNumber = (EditText) findViewById(R.id.editTextPhoneNumber);
        Button buttonActionDial = (Button) findViewById(R.id.buttonActionDial);
        Button buttonActionCall = (Button) findViewById(R.id.buttonActionCall);

        buttonActionDial.setOnClickListener(this);
        buttonActionCall.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {

        number = editTextPhoneNumber.getText().toString();

        switch (view.getId()) {
            case R.id.buttonActionDial:
                actionDial(view);
                break;
            case R.id.buttonActionCall:
                actionCall(view);
                break;
            default:
                break;
        }
    }

    void actionDial(View view) {
        Log.i(TAG, "actionDial: " + number);
        Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + number));
        startActivity(intent);
    }

    void actionCall(View view) {
        Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + number));
        startActivity(intent);

    }
}

5 adb

adb shell pm query-activities -a android.intent.action.DIAL

C:\>adb shell pm query-activities -a android.intent.action.DIAL
1 activities found:
  Activity #0:
    priority=0 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=true
    ActivityInfo:
      name=com.android.dialer.DialForwarderActivity
      packageName=com.android.dialer
      labelRes=0x7f120030 nonLocalizedLabel=null icon=0x7f0f0001 banner=0x0
      enabled=true exported=true directBootAware=true
      taskAffinity=com.android.dialer targetActivity=null persistableMode=PERSIST_ROOT_ONLY
      launchMode=2 flags=0x3102a4 privateFlags=0x2 theme=0x1030010
      screenOrientation=-1 configChanges=0x3 softInputMode=0x33
      lockTaskLaunchMode=LOCK_TASK_LAUNCH_MODE_DEFAULT
      resizeMode=RESIZE_MODE_RESIZEABLE
      knownActivityEmbeddingCerts={}
      ApplicationInfo:
        name=com.android.incallui.InCallApp
        packageName=com.android.dialer
        labelRes=0x7f120030 nonLocalizedLabel=null icon=0x7f0f0001 banner=0x0
        className=com.android.incallui.InCallApp
        processName=com.android.dialer
        taskAffinity=com.android.dialer
        uid=10212 flags=0x20c83e4d privateFlags=0xac101108 theme=0x0
        requiresSmallestWidthDp=0 compatibleWidthLimitDp=0 largestWidthLimitDp=0
        sourceDir=/system/priv-app/Dialer_MFV/Dialer_MFV.apk
        resourceDirs=[/product/overlay/NavigationBarMode3Button/NavigationBarMode3ButtonOverlay.apk]
        overlayPaths=[/product/overlay/NavigationBarMode3Button/NavigationBarMode3ButtonOverlay.apk, /data/resource-cache/com.android.systemui-neutral-NAlQ.frro, /data/resource-cache/com.android.systemui-accent-wJ0O.frro]
        seinfo=platform:privapp:targetSdkVersion=31
        seinfoUser=:complete
        dataDir=/data/user/0/com.android.dialer
        deviceProtectedDataDir=/data/user_de/0/com.android.dialer
        credentialProtectedDataDir=/data/user/0/com.android.dialer
        sharedLibraryFiles=[/product/framework/ims-ext-common.jar]
        enabled=true minSdkVersion=29 targetSdkVersion=31 versionCode=130000 targetSandboxVersion=1
        supportsRtl=true
        fullBackupContent=true
        crossProfile=false
        HiddenApiEnforcementPolicy=0
        usesNonSdkApi=false
        allowsPlaybackCapture=true
        nativeHeapZeroInitialized=0
        enableOnBackInvokedCallback=false
        createTimestamp=1938820

adb shell pm query-activities -a android.intent.action.CALL

C:\>adb shell pm query-activities -a android.intent.action.CALL
No activities found

6 参考资料

https://android.googlesource.com/platform/frameworks/base/+/refs/heads/android-s-beta-4/telephony/java/android/telephony/TelephonyManager.java

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值