基本信息
源码名称:WiFi编程例子
源码大小:1.33M
文件格式:.zip
开发语言:Java
更新时间:2015-02-03
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
package com.android.wifi.test;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class WifiActivity extends Activity implements IWifiConnectionInfoListener{
private PinGuoWifiSettings mWifiSettings=PinGuoWifiSettings.getInstance();
private Button mConnectBtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wifi);
mConnectBtn=(Button) findViewById(R.id.connect);
mConnectBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mWifiSettings.setStartPINGUOWifi(true);
}
});
mWifiSettings.init(this);
mWifiSettings.setListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_wifi, menu);
return true;
}
@Override
public void isWifiConnectionSuccess(boolean isWifiConnSuccess) {
if(isWifiConnSuccess){
Toast.makeText(this, "连接指定的Wifi成功", Toast.LENGTH_LONG).show();
}else{
showStartScanWifiDialog();
}
}
@Override
protected void onResume() {
mWifiSettings.onResume();
super.onResume();
}
@Override
protected void onPause() {
mWifiSettings.onPause();
super.onPause();
}
@Override
protected void onDestroy() {
mWifiSettings.onDestroy();
super.onDestroy();
}
AlertDialog mRetryAlertDialog;
private void showStartScanWifiDialog() {
if(mRetryAlertDialog!=null && mRetryAlertDialog.isShowing()){
return;
}
android.content.DialogInterface.OnClickListener positiveListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mRetryAlertDialog.cancel();
mWifiSettings.reset(true);
if (mWifiSettings.getListener() == null) {
mWifiSettings.setListener(WifiActivity.this);
}
}
};
android.content.DialogInterface.OnClickListener negativeListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
arg0.dismiss();
mWifiSettings.clear();
}
};
android.content.DialogInterface.OnKeyListener keyListener=new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
if(keyCode==KeyEvent.KEYCODE_BACK || keyCode==KeyEvent.KEYCODE_SEARCH){
dialog.dismiss();
mWifiSettings.clear();
return true;
}
return false;
}
};
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setTitle("温馨提示");
builder.setMessage("连接指定的wifi失败是否需要从新连接");
builder.setPositiveButton("从试", positiveListener);
builder.setNegativeButton("取消", negativeListener);
mRetryAlertDialog=builder.create();
mRetryAlertDialog.setOnKeyListener(keyListener);
mRetryAlertDialog.setCanceledOnTouchOutside(false);
mRetryAlertDialog.setCancelable(false);
mRetryAlertDialog.show();
}
}