【问题标题】:Android call broadcast receiverAndroid 呼叫广播接收器
【发布时间】:2014-04-09 10:52:31
【问题描述】:

我正在尝试创建呼叫广播接收器。我已成功创建广播接收器服务并添加了清单文件。 我的程序运行完美,但在模拟器中我可以在仅使用 DDMS 来电号码时调用(像这样)

现在我想在 divice 中运行我的应用程序。我希望 editext 的 toString 将是传入的数字。什么都是

我该如何解决? 下面是我的代码

public class MainActivity extends Activity {


private Button b;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    b = (Button) findViewById(R.id.ok);
    b.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent in = new Intent(getApplicationContext(),
                    IncomingCall.class);
            sendBroadcast(in);

        }
    });

}



public class IncomingCall extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    TelephonyManager tmgr = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);

    MyPhoneStateListener PhoneListener = new MyPhoneStateListener();

    tmgr.listen(PhoneListener, PhoneStateListener.LISTEN_CALL_STATE);

}

private class MyPhoneStateListener extends PhoneStateListener {
    public void onCallStateChanged(int state, String incomingNumber) {


        Log.d("MyPhoneListener", state + "   incoming no:" + incomingNumber);

    }
}

}

【问题讨论】:

    标签: android broadcastreceiver


    【解决方案1】:

    添加字符串编号=intent.getExtras().getString("incoming_number");在您的接收中,这里的数字是您将收到的数字

    【讨论】:

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