如何在电话管理器中查找拨出号码

发布于 2024-11-19 09:57:15 字数 355 浏览 3 评论 0原文

我正在使用这个:

public void onCallStateChanged(int state, String incomingNumber)

正在监听:

telephonyManager.listen(listener,PhoneStateListener.LISTEN_CALL_STATE);

我想知道拨出和拨入呼叫,但现在我只接到拨入呼叫(当状态更改正在响铃时)。谁能告诉我什么时候可以检测到拨出呼叫及其结束

还有一种方法可以在 Eclipse 模拟器中模拟拨出呼叫。能够通过 Eclipse 中的模拟器控制来对传入呼叫执行此操作。

I am using this:

public void onCallStateChanged(int state, String incomingNumber)

which is listening to:

telephonyManager.listen(listener,PhoneStateListener.LISTEN_CALL_STATE);

I want to know both outgoing and incoming calls but for now I only get incoming calls (when state changes is ringing). Can anyone tell me when can I detect outgoing call and its end

Also is there a way to simulate outgoing calls in Eclipse emulator. was able to do that for incoming calls via emulator control in eclipse.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寂寞陪衬 2024-11-26 09:57:15

使用带有 IntentFilter 意图 android.intent.action.NEW_OUTGOING_CALL 字符串参数的广播侦听器,并且不要忘记在 AndroidMenifest 中向 PROCESS_OUTGOING_CALLS 授予权限代码>.这会起作用。每当有拨出电话时,都会显示一条 toast 消息。代码如下。

public static final String outgoing = "android.intent.action.NEW_OUTGOING_CALL" ;
IntentFilter intentFilter = new IntentFilter(outgoing);
BroadcastReceiver OutGoingCallReceiver = new BroadcastReceiver()
{
    @Override
    public void onReceive(Context context, Intent intent) 
    {
        // TODO Auto-generated method stub
        String outgoingno = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        Toast.makeText(context, "outgoingnum =" + outgoingno,Toast.LENGTH_LONG).show();
    }
};
registerReceiver(brForOutgoingCall, intentFilter);

Use a broadcast listener with an intent android.intent.action.NEW_OUTGOING_CALL string parametrer for the IntentFilter and don't forget to give permission in AndroidMenifest to PROCESS_OUTGOING_CALLS. This will work. Whenever there is an outgoing call a toast message will be shown. Code is below.

public static final String outgoing = "android.intent.action.NEW_OUTGOING_CALL" ;
IntentFilter intentFilter = new IntentFilter(outgoing);
BroadcastReceiver OutGoingCallReceiver = new BroadcastReceiver()
{
    @Override
    public void onReceive(Context context, Intent intent) 
    {
        // TODO Auto-generated method stub
        String outgoingno = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        Toast.makeText(context, "outgoingnum =" + outgoingno,Toast.LENGTH_LONG).show();
    }
};
registerReceiver(brForOutgoingCall, intentFilter);
简单气质女生网名 2024-11-26 09:57:15

创建一个新类,例如 MyPhoneReceiver,从 BroadcastReceiver 扩展它,并实现 onReceive 方法。

public class MyPhoneReceiver extends BroadcastReceiver{
    @Override
    public void onReceive(Context context, Intent intent){

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

    }
}

在另一个类中,比如说 onCreate 方法中的 MainActivity.class 。例如。

    IntentFilter filter = new IntentFilter("android.intent.action.NEW_OUTGOING_CALL");
    MyPhoneReceiver myPhoneReceiver = new MyPhoneReceiver();
    registerReceiver(myPhoneReceiver,filter);

AndroidManifest.xml

<receiver
   android:name=".MyPhoneReceiver">
   <intent-filter>
     <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
  </intent-filter>
</receiver>

和 AndroidManifest.xml 中,添加:

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

Create a new class, let say MyPhoneReceiver, extends it from BroadcastReceiver, and implement onReceive method.

public class MyPhoneReceiver extends BroadcastReceiver{
    @Override
    public void onReceive(Context context, Intent intent){

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

    }
}

In another class, let say, MainActivity.class inside onCreate method. for example.

    IntentFilter filter = new IntentFilter("android.intent.action.NEW_OUTGOING_CALL");
    MyPhoneReceiver myPhoneReceiver = new MyPhoneReceiver();
    registerReceiver(myPhoneReceiver,filter);

In the AndroidManifest.xml

<receiver
   android:name=".MyPhoneReceiver">
   <intent-filter>
     <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
  </intent-filter>
</receiver>

and also in the AndroidManifest.xml, add:

<uses-permission
    android:name="android.permission.PROCESS_OUTGOING_CALLS">
</uses-permission>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文