【问题标题】:How to prevent outgoing call in android with a service?如何使用服务防止在android中拨出电话?
【发布时间】:2015-02-23 16:38:48
【问题描述】:

我想提供一项服务,当它处于活动状态并且用户按下通话按钮时,无论是在操作系统手机应用程序中还是在联系人中,它都会阻止拨出电话。我的意思是,我希望我的服务能够运行,而不是运行 android 调用服务。 有什么办法吗? 我真的是 android 编程的初学者,我对 android 服务不太了解。 我会很感激你帮助我。 非常感谢。

【问题讨论】:

标签: android android-service call system-calls background-service


【解决方案1】:

您必须为此使用 BroadcastReceiver。

在清单中你必须写

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

<receiver android:name=".OutGoingCallListener">
       <intent-filter android:priority="0">
           <action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
       </intent-filter>

   </receiver>

在从 BroadcastReceiver 扩展的类中,您必须编写

public class OutGoingCallListener extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    String number=intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER).toString();

       //if u want to block particular call then check number or else block all call in thid code

        setResultData(null);//Canceling call operation 
        Toast.makeText(context, "This call is not Allowed", Toast.LENGTH_LONG).show();


} }

【讨论】:

  • 它会显示消息,但不会结束通话!有什么办法吗?我认为 setResultData(null) 不起作用!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-29
  • 1970-01-01
  • 2010-10-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多