我是新手与Android的WIFI连接。我想创建应用程序以使用我的Android设备将消息发送到WIFI设备,所以为此我想问如何将我们的Android设备连接到WIFI设备以发送消息。
感谢和问候 阿米特
答案 0 :(得分:0)
你的问题我不清楚。您是否尝试连接到Wifi接入点并将数据传输到服务器或网站?
或者您想使用Wifi连接使用默认浏览器进行浏览吗?
此致 维奈
答案 1 :(得分:0)
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();
}
}};
}