可能重複:
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);
請僅粘貼有效的代碼。您似乎錯過了右括號,您應該嘗試使用Ctrl + Shift + f更好地設置您的代碼格式。 – WarrenFaith
重複,首先在提交問題前先google您的標題。 http://stackoverflow.com/questions/9390279/pass-a-value-from-activity-to-broadcastreceiver-and-start-a-service-from-the-bro – Tobrun