
package com.example.wifi;
import java.util.Iterator;
import java.util.List;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.google.ads.Ad;
import com.google.ads.AdListener;
import com.google.ads.AdRequest;
import com.google.ads.InterstitialAd;
public class MyWiFi extends Activity implements OnClickListener, AdListener {
// class provides the primary API for managing all aspects of Wi-Fi
// connectivity
// list of configured networks,currently active Wi-Fi network,
WifiManager wifiManager;
BroadcastReceiver broadcastReceiver;
Button wifibutton;
private static final String LOG_TAG = "InterstitialSample";
/** The interstitial ad. */
private InterstitialAd interstitialAd;
/** The button to reload the interstitial. */
private Button loadButton;
/** The button to show the interstitial. */
private Button showButton;
public String a152a434feea793;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.wifi);
interstitialAd = new InterstitialAd(this,a152a434feea793);
// Set the AdListener.
interstitialAd.setAdListener(this);
// Get a reference to the reload button. This button will load an
// interstitial ad.
loadButton = (Button) findViewById(R.id.loadButton);
// Get a reference to the show button. The button will start disabled,
// but
// will be enabled when the interstitial ad is loaded. After it is
// shown,
// it will be disabled again.
showButton = (Button) findViewById(R.id.showButton);
showButton.setText("Interstitial Not Ready");
showButton.setEnabled(false);
// Set the onClickListener for the buttons.
loadButton.setOnClickListener(this);
showButton.setOnClickListener(this);
// Setup UI
TextView setText = (TextView) findViewById(R.id.wifi_Text_View);
wifibutton = (Button) findViewById(R.id.wifi);
wifibutton.setOnClickListener(this);
registerReceiver(broadcastReceiver, new IntentFilter(
WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
wifibutton.setText("Wifi Clicked");
List<ScanResult> myResults = wifiManager.getScanResults();
Iterator<ScanResult> scanResult = myResults.iterator();
while (scanResult.hasNext())
;
Toast.makeText(MyWiFi.this, "enterd into WiFi Zone",
Toast.LENGTH_LONG).show();
wifiManager.getConfiguredNetworks();
}
};
}
@Override
public void onClick(View view) {
// If the load button was clicked, load an interstitial ad. Otherwise,
// if
// the show button was clicked, show the interstitial.
wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifiManager.startScan();
if (view == loadButton) {
// Disable the show button until the new ad is loaded.
showButton.setText("Loading Interstitial...");
showButton.setEnabled(false);
// Load the interstitial ad. Check logcat output for the hashed
// device ID
// to get test ads on a physical device.
AdRequest adRequest = new AdRequest();
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
interstitialAd.loadAd(adRequest);
} else if (view == showButton) {
// Disable the show button until another interstitial is loaded.
showButton.setText("Interstitial Not Ready");
showButton.setEnabled(false);
// Show the interstitial if it's loaded.
if (interstitialAd.isReady()) {
interstitialAd.show();
} else {
Log.d(LOG_TAG, "Interstitial ad was not ready to be shown.");
}
}
}
/** Called when an ad is clicked and about to return to the application. */
@Override
public void onDismissScreen(Ad ad) {
Log.d(LOG_TAG, "onDismissScreen");
Toast.makeText(this, "onDismissScreen", Toast.LENGTH_SHORT).show();
}
/** Called when an ad was not received. */
@Override
public void onFailedToReceiveAd(Ad ad, AdRequest.ErrorCode error) {
String message = "onFailedToReceiveAd (" + error + ")";
Log.d(LOG_TAG, message);
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
// Change the button text and disable the button.
if (ad == interstitialAd) {
showButton.setText("Failed to Receive Ad");
showButton.setEnabled(false);
}
}
/**
* Called when an ad is clicked and going to start a new Activity that will
* leave the application (e.g. breaking out to the Browser or Maps
* application).
*/
@Override
public void onLeaveApplication(Ad ad) {
Log.d(LOG_TAG, "onLeaveApplication");
Toast.makeText(this, "onLeaveApplication", Toast.LENGTH_SHORT).show();
}
/**
* Called when an Activity is created in front of the app (e.g. an
* interstitial is shown, or an ad is clicked and launches a new Activity).
*/
@Override
public void onPresentScreen(Ad ad) {
Log.d(LOG_TAG, "onPresentScreen");
Toast.makeText(this, "onPresentScreen", Toast.LENGTH_SHORT).show();
}
/** Called when an ad is received. */
@Override
public void onReceiveAd(Ad ad) {
Log.d(LOG_TAG, "onReceiveAd");
Toast.makeText(this, "onReceiveAd", Toast.LENGTH_SHORT).show();
// Change the button text and enable the button.
if (ad == interstitialAd) {
showButton.setText("Show Interstitial");
showButton.setEnabled(true);
}
}
}