2013-02-02 77 views
0

可能重複:
Pass a value from activity to broadcastreceiver and start a service from the broadcast receiver我如何將活動變量傳遞給廣播接收器?

我創建發送來電號碼藍牙,我想從活動通過管理員數量receiver.How我能做到這一點的應用程序?

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

請僅粘貼有效的代碼。您似乎錯過了右括號,您應該嘗試使用Ctrl + Shift + f更好地設置您的代碼格式。 – WarrenFaith

+0

重複,首先在提交問題前先google您的標題。 http://stackoverflow.com/questions/9390279/pass-a-value-from-activity-to-broadcastreceiver-and-start-a-service-from-the-bro – Tobrun

回答

0

試過這樣的事情?

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

rusume上的防雷代碼? registerReceiver(new IncomingCallReceiver(),new intentFilter(「android.intent.action.PHONE_STATE」)); –

+0

每當你想從接收者的任何地方傳遞號碼,如果已經註冊了相同的動作,它會調用接收者的onReceive方法。 – AAnkit

+0

Ok.Thanks very much !!! –

相關問題