开发者

android WIFI connectivity

I am new with WIFI connectivity with android. I want to create the application to send the messages to WIFI devices with my android devices so for this i want to ask how to con开发者_JAVA技巧nect our android device to WIFI devices to send the messages.

thanks and regards Amit


 WifiManager wifiManager;
 wifiManager = (WifiManager)      
 MyWifiActivity.this.getSystemService(Context.WIFI_SERVICE);
 DisplayWifiState();
    BroadcastReceiver myWifiReceiver = new BroadcastReceiver()
     {

      @Override
      public void onReceive(Context arg0, Intent arg1) {
       // TODO Auto-generated method stub
        NetworkInfo networkInfo = (NetworkInfo)               
                 arg1.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
       if(networkInfo.getType() == ConnectivityManager.TYPE_WIFI){
        DisplayWifiState();
       }
      }};
    this.registerReceiver(myWifiReceiver,new    
     IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));    


}


public void DisplayWifiState() 
{
    // TODO Auto-generated method stub
    AlertDialog.Builder alertbox = new AlertDialog.Builder(MyWifiActivity.this);


   if(!wifiManager.isWifiEnabled())
    { 
            Log.i("wifi", "wifi is in disabled mode");
            alertbox.setPositiveButton("Ok", new 
                                            DialogInterface.OnClickListener() 
            {

            @Override
            public void onClick(DialogInterface dialog, int which) 
            {
                // TODO Auto-generated method stub

            }
        });
            alertbox.setMessage("Wifi is disabled ! Please check Wifi 
                                                                     connection");
            alertbox.show();
    //if wifi is already in enabled
    if(wifiManager.isWifiEnabled())
    {
        Toast.makeText(MyWifiActivity.this,"Already on", Toast.LENGTH_LONG).show();
        Log.i("wifi", "wifi in on mode");
      }
  }
}
@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
     BroadcastReceiver myWifiReceiver = new BroadcastReceiver()
     {

      @Override
      public void onReceive(Context arg0, Intent arg1) {
       // TODO Auto-generated method stub
       NetworkInfo networkInfo = (NetworkInfo) 
                arg1.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
       if(networkInfo.getType() == ConnectivityManager.TYPE_WIFI){
        DisplayWifiState();
       }
      }};
}

@Override
protected void onStart() {
    // TODO Auto-generated method stub
    super.onStart();
     BroadcastReceiver myWifiReceiver = new BroadcastReceiver()
     {

      @Override
      public void onReceive(Context arg0, Intent arg1) {
       // TODO Auto-generated method stub
       NetworkInfo networkInfo = (NetworkInfo) 
                arg1.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
       if(networkInfo.getType() == ConnectivityManager.TYPE_WIFI){
        DisplayWifiState();
       }
      }};
}


You Question is not clear to me. Are you trying to connect to Wifi Access point and transfer data to the server or website?

Or do you want to browse using the default browser using Wifi connectivity?

Regards, Vinay

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜