Android等待WiFi扫描完成

时间:2013-05-04 08:18:55

标签: android broadcastreceiver android-wifi

我正在尝试等待无线扫描在广播接收器中完成!。

我有1个Activty(ChooseActivity extends Activity)和1个类(Scan)。

在我的Activity中,我调用Scan类来扫描wifi并在完成时返回boolean(true),这是代码。

我的目的是分离我的活动扫描,因为我在几个地方调用扫描类。

public class ChooseActivity extends Activity implements OnClickListener{

private int idMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_choose);

    idMap = this.getIntent().getExtras().getInt("ID_MAP");

    ((Button)this.findViewById(R.id.scan_button)).setOnClickListener(this);


}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch(v.getId()){
    case R.id.scan_button:
        Scan scan = new Scan();
        Toast.makeText(getApplicationContext(), " "+scan.scanHotspots(idMap), Toast.LENGTH_SHORT).show();

        break;
    }   
}
}

这是我的扫描课

public boolean scanHotspots(int idMap){

    wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);

    wifiManager.startScan();

    receiver = new Receiver();
    IntentFilter intentFilter = new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
    context.registerReceiver(receiver, intentFilter);

    //HERE I WANT STOP EXECUTION TO WAIT test VAIRABLE CHANGE STATUS    

    return test;
}


public class Receiver extends BroadcastReceiver{


    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        if(intent.getAction().equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION))
        {   
            test=true;  
        }
    }       
  }
}

提前谢谢。

0 个答案:

没有答案