Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何将变量从活动传递到广播接收器?_Android_Broadcastreceiver - Fatal编程技术网

Android 如何将变量从活动传递到广播接收器?

Android 如何将变量从活动传递到广播接收器?,android,broadcastreceiver,Android,Broadcastreceiver,可能重复: 我创建了一个将来电号码发送到蓝牙的应用程序,并希望将管理员号码从活动传递到接收器。我如何才能做到这一点 public void onResume() { super.onResume(); registerReceiver(new IncomingCallReceiver(), new intentFilter("android.intent.action.PHONE_STATE")); @Override public void onReceiv

可能重复:

我创建了一个将来电号码发送到蓝牙的应用程序,并希望将管理员号码从活动传递到接收器。我如何才能做到这一点

  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);

试过这样的吗

   Intent intent = new Intent("android.intent.action.PHONE_STATE");
    intent.putExtra("admin_no","9999999"); // change number here.
    sendBroadcast(intent);

请仅粘贴有效代码。你似乎错过了结束括号,你应该尝试使用ctrl+shift+f来更好地格式化你的代码。在rusume上的我的代码之后?registerReceiver(新IncomingCallReceiver(),新intentFilter(“android.intent.action.PHONE_STATE”);无论何时,只要您想将数字从任何位置传递给接收方,若已经注册了相同的操作,它就会调用receivers onReceive方法