【问题标题】:To block the out going call from my android app.阻止来自我的 android 应用程序的拨出电话。
【发布时间】:2018-05-30 11:45:53
【问题描述】:

我想制作一个应用程序,一旦应用程序启动,它将显示两个按钮(启动和停止按钮),一旦用户单击启动按钮,调用功能将被阻止一段时间,直到用户再次启动应用程序并单击停止按钮以停止此功能。任何帮助请其紧急

简而言之,我会告诉我我想通过仅使用此活动来阻止来自手机的拨出电话

请问有什么办法吗???

【问题讨论】:

标签: android android-intent


【解决方案1】:

您可以使用广播接收器的 onReceive 方法中的 setResultData(null) 函数来阻止呼出。

public class BlockOutgoing extends BroadcastReceiver
{
    String number;
    @Override
    public void onReceive(Context context, Intent intent) 
    {
        Log.d("12280", "asdasNumber is-->> " + number);
        number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        setResultData(null);
        Toast.makeText(context, "Outgoing Call Blocked" , 5000).show();

    }
}

在manifest文件中,需要像这样注册receiver,

<receiver
            android:name=".BlockOutgoing"
            android:label="@string/app_name" >
            <intent-filter android:priority="1">

<action android:name="android.intent.action.NEW_OUTGOING_CALL" />

            </intent-filter>
        </receiver>

还要定义拦截呼出的权限,

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

编辑- 要取消注册广播接收器,请关注此link

【讨论】:

  • 谢谢它的工作,对不起,你能告诉我现在如何取消这个广播
  • 是的,我试过了,但它对我没有用,所以有没有其他方法可以让我解释一下我的问题......当我点击第一个按钮时,我有拖曳按钮它应该当我再次运行我的应用程序时,开始广播并停止外出通话,如果我点击第二个按钮,那么我猜广播接收器应该启动或停止,我的通话应该再次开始
【解决方案2】:

公共类 BlockOutgoing 扩展 BroadcastReceiver {

String number;
@SuppressLint("WrongConstant")
@Override
public void onReceive(Context context, Intent intent)
{
    // Log.d("12280", "asdasNumber is-->> " + number);
    number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
    setResultData(null);
    Toast.makeText(context, "Outgoing Call Blocked" , 5000).show();

}

}

   <receiver
        android:name=".BlockOutgoing"
        android:label="@string/app_name" >
        <intent-filter android:priority="1">
            <action android:name="android.intent.action.NEW_OUTGOING_CALL" />

        </intent-filter>
    </receiver>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多