0

可能重复:
将值从活动传递到广播接收器并从广播接收器启动服务

我创建了一个将来电号码发送到蓝牙的应用程序,我想将管理员号码从活动传递给接收器。我该怎么做?

  public void onResume() {
   super.onResume();

  registerReceiver(new IncomingCallReceiver(), new  intentFilter("android.intent.action.PHONE_STATE"));

   @Override
    public void onReceive(Context context, Intent intent) {
            Bundle bundle = intent.getExtras();

            String msg2 = intent.getStringExtra("admin_no");

            if(null == bundle)
                    return;

            Log.i("IncomingCallReceiver",bundle.toString());

            String state = bundle.getString(TelephonyManager.EXTRA_STATE);

            Log.i("IncomingCallReceiver","State: "+ state);

            if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING))
            {
                    String phonenumber = bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
4

1 回答 1

0

尝试过这样的事情?

   Intent intent = new Intent("android.intent.action.PHONE_STATE");
    intent.putExtra("admin_no","9999999"); // change number here.
    sendBroadcast(intent);
于 2013-02-02T12:55:24.157 回答