如何在android中阻止呼叫

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1083527/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 02:40:40  来源:igfitidea点击:

How to block calls in android

androidphone-callincoming-callcallblocking

提问by Anurag Uniyal

I want to block calls from few numbers, for that I want to write a app of my own. So what are the APIs which I should be using?

我想阻止来自几个号码的呼叫,为此我想编写一个自己的应用程序。那么我应该使用哪些 API?

Basically I want to get notified when a call comes, i want to compare numbers if it is what i want to block, i want to cut the call or mute it or if possible mute it and record it.

基本上我想在来电时得到通知,我想比较数字是否是我想阻止的,我想挂断电话或将其静音,或者如果可能的话将其静音并记录下来。

回答by foryou

OMG!!! YES, WE CAN DO THAT!!! I was going to kill myself after severe 24 hours of investigating and discovering... But I've found "fresh" solution!

我的天啊!!!是的,我们可以做到!!!经过严格的 24 小时调查和发现,我打算自杀……但我找到了“新鲜”的解决方案!

// "cheat" with Java reflection to gain access to TelephonyManager's
// ITelephony getter
Class c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
telephonyService = (ITelephony)m.invoke(tm);

all all all of hundreds of people who wants to develop their call-control software visit this start point

数百名想要开发他们的呼叫控制软件的人都访问这个起点

there is a project. and there are important comments (and credits)

有一个项目。并且有重要的评论(和学分)

briefly: copy aidl file, add permissions to manifest, copy-paste source for telephony management )))

简而言之:复制aidl文件,添加清单权限,复制粘贴电话管理源)))

Some more info for you. AT commands you can send only if you are rooted. Than you can kill system process and send commands but you will need a reboot to allow your phone to receive and send calls =)))

为您提供更多信息。仅当您有 root 权限时才能发送 AT 命令。您可以杀死系统进程并发送命令,但您需要重新启动才能让您的手机接收和发送电话 =)))

I'm very hapy =) Now my Shake2MuteCall will get an update !

我很高兴 =) 现在我的 Shake2MuteCall 将得到更新!

回答by foryou

It is possible and you don't need to code it on your own.

这是可能的,您不需要自己编写代码。

Just set the ringer volume to zero and vibration to none if incomingNumber equals an empty string. Thats it ...

如果incomingNumber 等于空字符串,只需将铃声音量设置为零并将振动设置为无。就是这样 ...

Its just done for you with the application Nostalk from Android Market. Just give it a try ...

它刚刚通过 Android Market 的应用程序 Nostalk 为您完成。试试吧...

回答by Amit Vaghela

In android-N, this feature is included in it. check Number-blockingupdate for android N

在android-N中,这个特性就包含在里面了。检查android N 的号码阻止更新

Android N now supports number-blocking in the platform and provides a framework API to let service providers maintain a blocked-number list. The default SMS app, the default phone app, and provider apps can read from and write to the blocked-number list. The list is not accessible to other app.

Android N 现在支持平台中的号码阻塞,并提供框架 API 来让服务提供商维护一个阻塞号码列表。默认 SMS 应用程序、默认电话应用程序和提供商应用程序可以读取和写入阻止号码列表。其他应用程序无法访问该列表。

advantage of are:

优点是:

  1. Numbers blocked on calls are also blocked on texts
  2. Blocked numbers can persist across resets and devices through the Backup & Restore feature
  3. Multiple apps can use the same blocked numbers list
  1. 通话中被屏蔽的号码也会被短信屏蔽
  2. 通过备份和恢复功能,被阻止的号码可以在重置和设备之间保持不变
  3. 多个应用程序可以使用相同的阻止号码列表

For more information, see android.provider.BlockedNumberContract

有关更多信息,请参阅 android.provider.BlockedNumberContract

Update an existing project.

更新现有项目。

To compile your app against the Android N platform, you need to use the Java 8 Developer Kit (JDK 8), and in order to use some tools with Android Studio 2.1, you need to install the Java 8 Runtime Environment (JRE 8).

要针对Android N 平台编译您的应用程序,您需要使用Java 8 Developer Kit (JDK 8),并且为了在Android Studio 2.1 中使用某些工具,您需要安装Java 8 Runtime Environment (JRE 8)

Open the build.gradlefile for your module and update the values as follows:

打开模块的build.gradle文件并按如下方式更新值:

android {
  compileSdkVersion 'android-N'
  buildToolsVersion 24.0.0 rc1
  ...

  defaultConfig {
     minSdkVersion 'N'
     targetSdkVersion 'N'
     ...
  }
  ...
}

回答by Cogsy

You could just re-direct specific numbers in your contacts to your voice-mail. That's already supported.

您可以将联系人中的特定号码重定向到您的语音邮件。那已经支持了。

Otherwise I guess the documentation for 'Contacts' would be a good place to start looking.

否则,我想“联系人”的文档将是一个开始寻找的好地方。

回答by android developer

You can do it by listening to phone call events . You do it by having a BroadcastReceiver to PHONE_STATE and to NEW_OUTGOING_CALL. You find there what is the phone number.

你可以通过监听电话事件来做到这一点。您可以通过将 BroadcastReceiver 连接到 PHONE_STATE 和 NEW_OUTGOING_CALL 来实现。你可以在那里找到电话号码。

Then when you decide to end the call, this is a bit tricky, because only from Android P it's guaranteed to work. Check here.

然后当您决定结束通话时,这有点棘手,因为只有在 Android P 中它才能保证工作。检查这里