Thursday, April 3, 2014

How To Scan QR Code Using AVFoundation Framework

iOS 7 brings a wealth of new features that set it apart from all other mobile operating systems. Both major additions and minor improvements have been made, offering developers new or updated frameworks and APIs to work with, and the opportunity to provide single users with a much richer experience. The AVFoundation framework is just one of them, as it has accepted great enhancements and new class additions that make even more tools available. One of the new features that the AVFoundation incorporates, is the ability to discover and read bar codes in real-time, and one of the supported bar code types that we especially interested in at this tutorial, is the QR Code.
A Quick Response Code (QR Code) is actually a two-dimensional (2D) barcode. Instead of the vertical lines like those that the well-known barcode contains, a QR Code can have its lines designed in both horizontal and vertical directions. The data that’s being encapsulated into such a code, is read by devices specificly designed for this job, or by smart devices (smartphones, tablets) using the appropriate software. A QR Code can store a great amount of data (in relation to the ordinary barcode), so there is a variety of information that can be encoded in it. Some typical content examples of a QR Code are:
  • URL
  • Phone number
  • Simple text
  • SMS text
QR Codes are used mainly for marketing reasons, but not only. One can create a QR Code to use on its website, or on any other place that may wants.
QRCode Featured
undefined
undefined
Thanks to iOS 7, creating applications that can scan and translate a QR Code has been really a piece of cake. So, if you have ever been tempted to create such an app, or you are just curious to learn more about all these, then just keep reading!

Demo App Overview

The demo application that we are going to implement in this tutorial is fairly simple and straightforward. It is going to be universal, meaning that it will be able to work in both iPhone and iPad, so you can run it on any device you might have with iOS 7 installed on it. Right next is shown a figure of the outcome in iPhone:
QR Code Demo App for iPhone
For the iPad, the interface is more or less the same:
QR Code Demo App for iPad
Before I proceed to a discussion regarding the demo figures above, it’s important to underline at this point that any barcode scanning, including QR codes, is totally based on video capturing, that’s why AVFoundation framework supports the barcode reading feature. Keep this info on mind, as it’s the starting point for the entire application.
Even though it’s not hard to figure out what all subviews layed on the interface are for, I’ll make a quick reference on them, so it’ll become absolutely clear what our app is going to contain.
So, beginning from top to bottom, at first there is a UIView view, which is going to be the container for the preview layer of the video captured by the device. A UILabel exists on top of it, simply prompting to tap on the start button to begin reading a QR code. Right next, another UILabel plays the role of the status log while a code is being read, and finally a toolbar lies at the bottom of the view, with one bar button item only which will be used to start and stop the capturing.
Here is how the demo application is going to work:
Initially, when the app is launched, the interface shown in the figure above is first displayed. By tapping the start bar button at the toolbar, a video capturing session is initiated in order to scan for QR codes. Once that happens, the start button’s title changes to Stop, while its functionality changes as well with aim to enable us to stop capturing at any time.
The status label is going to show three different messages, depending on the scanning state:
  1. When a code scanning is not yet performed.
  2. When a code scanning is in progress.
  3. When a scan has been completed and the contained information has been translated and is ready to be displayed.
Also, a sound effect (a beep sound) is being played every time a QR code has been successfully read to make our app more vivid and interactive.
Note that this application cannot be tested on the Simulator, neither to a device without a camera, as everything is based on real-time video capturing. Therefore, you’ll need to connect your device and run it there if you want to see the application live.

Building the Demo App

Ready to take off? Let’s begin by launching the Xcode. In the Welcome screen, select to create a new project.
Xcode Welcome
In the project creation guide under the iOS section, select the Application category and then select the Single View Application template. Click Next to proceed.
Select Xcode Project Template
Next, give a name to the project. In the Product Name field add the QRCodeReader value. Also, in theDevices drop down menu select the Universal value in order to let your app run in both iPhone and iPad devices. Click Next to continue.
Set Xcode Project Details
In the last window, select a directory to save the project and click on the Create button.
Xcode creates the project and makes any necessary initial, default configuration is required. Now we are ready to start building.

Setting Up the User Interface

Our application is universal, so it’s needed to create the interface for both the iPhone and the iPad. Let’s begin from the iPhone, so click on the Main_iPhone.storyboard to bring the Interface Builder up. Initially, you should see only an empty view controller, just like the next image:
Initial Interface for QR Code Demo
Here is a list of all the controls you need to drag and drop in the view of the view controller, along with all properties that need to be set in order to create an interface similar to the wanted one.
  • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">UIView
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">Frame: X=20 Y=40 Width=280 Height=350
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">Background Color: Black
  • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">UILabel Add this as a subview to the previous view
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">Frame: X=17 Y=164 Width=247 Height=21
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">Color: White
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">Text: Tap on Start! to read a QR Code
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">Font: System Bold 15.0
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">Text Alignment: Center
  • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">UILabel
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">Frame: X=20 Y=448 Width=280 Height=21
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">Color: R=0 G=255 B=0
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">Text: QR Code Reader is not yet running…
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">Font: System 15.0
  • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">UIToolbar
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">Frame: X=0 Y=524 Width=320 Height=44
  • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">UIBarButtonItem (already existing on the toolbar)
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">Title: Start!
  • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">UIBarButtonItem
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">New Flexible Space Bar Button Item on the left side of the start button.
  • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">UIBarButtonItem
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">New Flexible Space Bar Button Item on the right side of the start button.
After you’re done, the interface should look like the next one:
QR Code iPhone Interface
Here is the respective list with all the controls required to setup the interface for the iPad, along with the properties you need to configure.
  • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">UIView
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">Frame: X=44 Y=40 Width=680 Height=840
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">Background Color: Black
  • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">UILabel Add this as a subview to the previous view
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">Frame: X=20 Y=329 Width=640 Height=41
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">Color: White
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">Text: Tap on Start! to read a QR Code
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">Font: System Bold 24.0
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">Text Alignment: Center
  • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">UILabel
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">Frame: X=20 Y=448 Width=280 Height=21
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">Color: R=0 G=255 B=0
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">Text: QR Code Reader is not yet running…
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">Font: System 17.0
  • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">UIToolbar
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">Frame: X=0 Y=980 Width=768 Height=44
  • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">UIBarButtonItem (already existing on the toolbar)
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">Title: Start!
  • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">UIBarButtonItem
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">New Flexible Space Bar Button Item at the left side of the start button.
  • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">UIBarButtonItem
    • http://www.appcoda.com/wp-content/themes/eleven40/images/list.png); list-style-type: none; word-wrap: break-word; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">New Flexible Space Bar Button Item at the right side of the start button.
Here is how the iPad interface should now look like:
QR Code for iPad Interface
So far, so good. For both devices the interface is ready, but we are not finished yet. We need to create IBOutlet methods and connect them to the controls we need to touch in code. Open theViewController.h file, and add the following IBOutlet property declarations:
1
2
3
4
5
6
7
@interface ViewController : UIViewController

@property (weak, nonatomic) IBOutlet UIView *viewPreview;
@property (weak, nonatomic) IBOutlet UILabel *lblStatus;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *bbitemStart;

@end
As you see, we need properties for the video container view, the status label and the start bar button item. Besides these properties however, now it’s the best time to declare an IBAction method which we will connect to the start bar button item in order to make it start and stop video capturing. Therefore, right after the last property, add the next line:
1- (IBAction)startStopReading:(id)sender;
Let’s make the connections now. Open the Main_iPhone.storyboard file and Control-Click or Right-Click on the View Controller object, inside the Document Outline pane. In the black popup window that appears, you can see all of the IBOutlet properties that were previously declared under theOutlets section. For each one of them, click on the circle on the right side and drag and drop to the appropriate control. The next image will make this procedure clear:
Connect IBOutlet
Follow the same steps to connect the startStopReading: IBAction method to the start bar button item. The IBAction method exists under the Received Actions section in the black popup window.
As a reminder, don’t forget to do the same job in the Main_iPad.storyboard file.

QR Code Reading Implementation

Up to now we have created the project, we have setup the interface and we have done all necessary configurations on the controls of our application. Time to make a deep dive and write the necessary code that will give life to the most important feature, the QR code reading.
The best point to start writing code is our IBAction method, the startStopReading:, which is already declared and connected to the start bar button item. However, before we begin implementing it, let’s remember something; while I was presenting the demo app and the way it’s going to work, I said that once the video capturing begins, the start button becomes a stop button and vice versa. Programmatically, that means that we need to find a way that lets the app know when to perform the start functionality, and when to perform the stop functionality. Well, what’s a better way than a flag?
If you haven’t done already, open the ViewController.m file. Navigate yourself at the top of it, in the private interface section, and add the following flag:
1
2
3
@interface ViewController ()
@property (nonatomic) BOOL isReading;
@end
It’s quite obvious by its name that, when the isReading variable is NO (false), then the app is not scanning for a QR code and the video capture functionality should start when the bar button is tapped. The exact opposite happens when the variable is set to YES (true). I would strongly advice that when declaring member variables, then the next step that should be done is to give them their initial value, as the most probable scenario is that you are going to forget to do so later. So, let’s go inside theviewDidLoad method to set the initial value for our flag:
1
2
3
4
5
6
- (void)viewDidLoad
{
    [super viewDidLoad];

    _isReading = NO;
}
Now we are absolutely ready to implement the startStopReading: IBAction method. Write the following code snippet and then we’ll discuss it a bit:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
- (IBAction)startStopReading:(id)sender {
    if (!_isReading) {
        if ([self startReading]) {
            [_bbitemStart setTitle:@"Stop"];
            [_lblStatus setText:@"Scanning for QR Code..."];
        }
    }
    else{
        [self stopReading];
        [_bbitemStart setTitle:@"Start!"];
    }  
   
    _isReading = !_isReading;
}
At first, we check if the isReading flag is NO, meaning that currently no QR code scanning is taking place. If that’s the case, then we call the startReading method, which we are going to implement in a while. If everything goes well when calling this method, then we change the bar button item’s title toStop and we set another message on the status label. However, if the app is currently scanning for a QR code and the isReading flag is YES, then we call the stopReading method (yes, we’ll implement this one later too), and we also set the title of the bar button item to Start!. Finally, no matter what the case is, we set in the isReading flag the exact opposite value of the one that currently has.
As you just saw, we used two methods that we haven’t yet implemented. We will begin doing so by thestartReading, which as you imagine, is one of the most important methods in this app. First of all, we need to declare it, so go to the private interface section and add the next declaration:
1
2
3
4
5
6
@interface ViewController ()
@property (nonatomic) BOOL isReading;

-(BOOL)startReading;

@end
Don’t leave there yet. Before we move to implementation, we need to declare a couple of objects that we’ll need right next. So, add the new lines shown in the snippet below:
1
2
3
4
5
6
7
8
@interface ViewController ()
@property (nonatomic) BOOL isReading;

@property (nonatomic, strong) AVCaptureSession *captureSession;
@property (nonatomic, strong) AVCaptureVideoPreviewLayer *videoPreviewLayer;

-(BOOL)startReading;
@end
At this point Xcode will probably complain about the AVCaptureSession and theAVCaptureVideoPreviewLayer classes. That’s because we still haven’t imported the AVFoundation framework. Before we fix this, go into the viewDidLoad method and make the captureSession object nil.
1
2
3
4
5
6
7
- (void)viewDidLoad
{
    [super viewDidLoad];
    _isReading = NO;
   
    _captureSession = nil;
}
Now, open the ViewController.h file and at the top of it, import the AVFoundation framework.
1#import <AVFoundation/AVFoundation.h>

Sunday, March 2, 2014

[Android Useful Examples] Android Wi-Fi Tutorial

Android allows applications to access to view the access the state of the wirless connections at very low level. Application can access almost all the information of a wifi connection.
The information that an application can access includes connected network's link speed,IP address, negotiation state, other networks information. Applications can also scan, add, save, terminate and initiate Wi-Fi connections.
Android provides WifiManager API to manage all aspects of WIFI connectivity. We can instantiate this class by calling getSystemService method. Its syntax is given below:
WifiManager mainWifiObj;
mainWifiObj =(WifiManager) getSystemService(Context.WIFI_SERVICE);
undefined
In order to scan a list of wireless networks, you also need to register your BroadcastReceiver. It can be registered using registerReceiver method with argument of your reciever class object. Its sytanx is given below:
classWifiScanReceiverextendsBroadcastReceiver{
   publicvoid onReceive(Context c,Intent intent){
   }}WifiScanReceiver wifiReciever =newWifiScanReceiver();
registerReceiver(wifiReciever,newIntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));  
The wifi scan can be start by calling the startScan method of the WifiManager class. This method returns a list of ScanResult objects. You can access any object by calling the get method of list. Its syntax is given below:
List<ScanResult> wifiScanList = mainWifiObj.getScanResults();String data = wifiScanList.get(0).toString();
Apart from just Scanning , you can have more control over your WIFI by using the methods defined in WifiManager class. They are listed as follows:
Sr.NoMethod & Description
1addNetwork(WifiConfiguration config)
This method add a new network description to the set of configured networks.
2createWifiLock(String tag)
This method creates a new WifiLock.
3disconnect()
This method disassociate from the currently active access point.
4enableNetwork(int netId, boolean disableOthers)
This method allow a previously configured network to be associated with.
5getWifiState()
This method gets the Wi-Fi enabled state
6isWifiEnabled()
This method return whether Wi-Fi is enabled or disabled.
7setWifiEnabled(boolean enabled)
This method enable or disable Wi-Fi.
8updateNetwork(WifiConfiguration config)
This method update the network description of an existing configured network.

Example

Here is an example demonstrating the use of WIFI. It creates a basic application that scans a list of wirless networks and populate them in a list view.
To experiment with this example , you need to run this on an actual device on which wifi is turned on.
StepsDescription
1You will use Eclipse IDE to create an Android application and name it as WIFI under a package com.example.wifi. While creating this project, make sure you Target SDK and Compile With at the latest version of Android SDK to use higher levels of APIs.
2Modify src/MainActivity.java file to add WebView code.
3Modify the res/layout/activity_main to add respective XML components
4Modify the AndroidManifest.xml to add the necessary permissions
5Run the application and choose a running android device and install the application on it and verify the results.
Following is the content of the modifed main activity file src/com.example.wifi/MainActivity.java.
package com.example.wifi;

import java.util.List;

import android.annotation.SuppressLint;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.widget.ArrayAdapter;import android.widget.ListView;import android.widget.Toast;

publicclassMainActivityextendsActivity{

   WifiManager mainWifiObj;
   WifiScanReceiver wifiReciever;
   ListView list;
   String wifis[];
   publicvoid onCreate(Bundle savedInstanceState){
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      list =(ListView)findViewById(R.id.listView1);
      mainWifiObj =(WifiManager) getSystemService(Context.WIFI_SERVICE);
      wifiReciever =newWifiScanReceiver();
      mainWifiObj.startScan();
   }


   protectedvoid onPause(){
      unregisterReceiver(wifiReciever);
      super.onPause();
   }

   protectedvoid onResume(){
      registerReceiver(wifiReciever,newIntentFilter(
      WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
      super.onResume();
   }

   classWifiScanReceiverextendsBroadcastReceiver{
      @SuppressLint("UseValueOf")
      publicvoid onReceive(Context c,Intent intent){
         List<ScanResult> wifiScanList = mainWifiObj.getScanResults();
         wifis =newString[wifiScanList.size()];
         for(int i =0; i < wifiScanList.size(); i++){
            wifis[i]=((wifiScanList.get(i)).toString());
         }

         list.setAdapter(newArrayAdapter<String>(getApplicationContext(),
         android.R.layout.simple_list_item_1,wifis));
      }
   }

}
Following is the modified content of the xml res/layout/activity_main.xml.
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:paddingBottom="@dimen/activity_vertical_margin"
   android:paddingLeft="@dimen/activity_horizontal_margin"
   android:paddingRight="@dimen/activity_horizontal_margin"
   android:paddingTop="@dimen/activity_vertical_margin"
   tools:context=".MainActivity">

   <ListView
      android:id="@+id/listView1"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentTop="true"
      android:layout_centerHorizontal="true"
      android:drawSelectorOnTop="false"
      android:background="@android:color/background_dark"
      android:listSelector="@android:color/darker_gray">

   </ListView></RelativeLayout>
Following is the content of AndroidManifest.xml file.
<?xml version="1.0" encoding="utf-8"?><manifestxmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example.wifi"
   android:versionCode="1"
   android:versionName="1.0">

   <uses-sdk
      android:minSdkVersion="14"
      android:targetSdkVersion="17"/>

   <uses-permissionandroid:name="android.permission.ACCESS_WIFI_STATE"/>
   <uses-permissionandroid:name="android.permission.CHANGE_WIFI_STATE"/>

   <application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme">
      <activity
         android:name="com.example.wifi.MainActivity"
         android:label="@string/app_name">
         <intent-filter>
            <actionandroid:name="android.intent.action.MAIN"/>

            <categoryandroid:name="android.intent.category.LAUNCHER"/>
         </intent-filter>
      </activity>
    <activity
         android:name="com.example.wifi.ListWifiActivity"
         android:label="@string/title_activity_list_wifi">
      </activity>
   </application></manifest>

Let's try to run your WIFI application. I assume you have connected your actual Android Mobile device with your computer. To run the app from Eclipse, open one of your project's activity files and click Run Eclipse Run Icon icon from the toolbar. Before starting your application, Eclipse will display following window to select an option where you want to run your Android application.
Anroid Wi-Fi Tutorial
Select your mobile device as an option and then check your mobile device which will display your mobile screen filled with wireless networks around you. It is shown below:
Anroid Wi-Fi Tutorial
Note the information that has been returned to you. It contains much information about each of the wireless network detected.
undefined

[Android Useful Examples] Android Widgtets Tutorial

 widget is a small gadget or control of your android application placed on the home screen. Widgets can be very handy as they allow you to put your favourite applications on your homescreen in order to quickly access them. You have probably seen some common widgets , such as music widget , weather widget , clock widget e.t.c
Widgets could be of many types such as information widgets, collection widgets, control widgets and hybrid widgets. Android provides us a complete framework to develop our own widgets.

Widget - XML file

In order to create an application widget , first thing you need is AppWidgetProviderInfo object, which you will define in a seperate widget XML file. In order to do that, right click on your project and create a new folder called xml. Now right click on the newly created folder and create a new XML file. The resource type of the XML file should be set to AppWidgetProvider. In the xml file, define some properties which are as follows:
<appwidget-provider 
   xmlns:android="http://schemas.android.com/apk/res/android" 
   android:minWidth="146dp" 
   android:updatePeriodMillis="0" 
   android:minHeight="146dp" 
   android:initialLayout="@layout/activity_main"></appwidget-provider>

Customize Joomla Extensions With Override

We all know that Joomla is a fantastic CMS for building professional websites. The JED (Joomla Extension Directory) is full of components, modules and plugins that can add almost any type of functionality to any Joomla site. That's great and all but what if you find a component or module that gives the functionality needed but the output and layout is not exactly what you want? A big mistake that some developers and webmasters make is going in and editing the core code of an extension. Joomla makes it easy by allowing overrides.

What is an Override?

An override is a copy of an extensions layout/template file that is placed in your Joomla template directory. You can then customize it to your liking. The difference with doing this as oppose to just editing the file in the extension directory is that when you upgrade Joomla or the extension, your changes will not be replaced with the new versions. Joomla knows to look in the overridden file first, then the actual extensions file.
undefined

How do I Create an Override?

Creating an override is easy. For the sake of this tutorial, let's say that we want to edit the output of the login page. By default, the login page has 3 links in an unordered list (forgot password, forgot username and don't have an account).
Default component frontend
For the sake of this tutorial, let's say that we do not want the last "Don't have an account" link and we also do not want them in a list, we just want the 2 other links side by side. The changes we make do not really matter at this point. It is just to show you how an override works. By default, Joomla uses the com_users component to handle login and registration. The com_users component has multiple views/layouts. We can see them by going tojoomlasite/components/com_users/views
Component view files
You can see there are 5 different views. We want to edit the login page so we want the loginfolder/view. If you click on that, you will then see a tmpl folder. This is the template for this particular view. In the tmpl folder is where the layout files are located. Just about all component and module tmpl folders have a default.php file. Some components such as this have additional template files. The Users component login view has default.php, default_login.php anddefault_logout.php.
Component layout files
The default_login.php folder is the one we need to edit the login form page. So we need to take that file and place it into the Joomla template folder structure. Go to your main Joomla template folder. This would be in joomlasite/templates/yourtemplatname. You need to create a new folder called html. In that html folder, create another called com_users and then in that, one more folder called login. This is where you want to place the default_login.php file that you copied. So the full path would bejoomlasite/templates/yourtemplatename/html/com_users/login/default_login.php

Editing the default_login.php File

So now if we make some changes and save the default_login.php override file, Joomla will look to this file first. Let's make the small change of removing the list and the last link In the newdefault_login.php file, you will see the following code
Default component code
It is the unordered list with the 3 links. Let's edit this by removing the list tags and getting rid of the 3rd link along with the if statement. So it will look like this
New component frontend
Now save the file and go back to your frontend login page.
New component frontend
You can now see that the list formatting and the 3rd link are both gone. So now if you update Joomla core files or update the com_users component, this change would stay with the site as oppose to just being written over. This is extremely useful in Joomla web development. You can do this with any component or module that follows the standard Joomla structure. Do you have any extensions in mind that you would like to tweak to your liking? Let us know in the comment section