Search for:
Android – Useful Resources

Android &-8211; Useful Resources &-8211; this Article or News was published on this date:2019-05-13 19:48:39 kindly share it with friends if you find it helpful

Android &-8211; Useful Resources


Advertisements


The following resources contain additional information on Android. Please use them to get more in-depth knowledge on this topic.

Useful Links on Android

Useful Books on Android

  • The Android Developer's Cookbook
  • Android Programming Painless
  • Professional Android 4 Application Development
  • Android Programming
  • Beginning Android 4 Application Development
  • Programming Android

To enlist your site on this page, please drop an email to [email protected]



Advertisements

Android Video Tutorials

Android &-8211; Home

Android &-8211; Overview

Android &-8211; Environment Setup

Android &-8211; Architecture

Android &-8211; Application Components

Android &-8211; Hello World Example

Android &-8211; Resources

Android &-8211; Activities

Android &-8211; Services

Android &-8211; Broadcast Receivers

Android &-8211; Content Providers

Android &-8211; Fragments

Android &-8211; Intents/Filters

Android &-8211; UI Layouts

Android &-8211; UI Controls

Android &-8211; Event Handling

Android &-8211; Styles and Themes

Android &-8211; Custom Components

Android &-8211; Drag and Drop

Android &-8211; Notifications

Location Based Services

Android &-8211; Sending Email

Android &-8211; Sending SMS

Android &-8211; Phone Calls

Publishing Android Application

Android &-8211; Alert Dialoges

Android &-8211; Animations

Android &-8211; Audio Capture

Android &-8211; AudioManager

Android &-8211; Auto Complete

Android &-8211; Best Practices

Android &-8211; Bluetooth

Android &-8211; Camera

Android &-8211; Clipboard

Android &-8211; Custom Fonts

Android &-8211; Data Backup

Android &-8211; Developer Tools

Android &-8211; Emulator

Android &-8211; Facebook Integration

Android &-8211; Gestures

Android &-8211; Google Maps

Android &-8211; Image Effects

Android &-8211; ImageSwitcher

Android &-8211; Internal Storage

Android &-8211; JetPlayer

Android &-8211; JSON Parser

Android &-8211; Linkedin Integration

Android &-8211; Loading Spinner

Android &-8211; Localization

Android &-8211; Login Screen

Android &-8211; MediaPlayer

Android &-8211; Multitouch

Android &-8211; Navigation

Android &-8211; Network Connection

Android &-8211; NFC Guide

Android &-8211; PHP/MySQL

Android &-8211; Progress Circle

Android &-8211; ProgressBar

Android &-8211; Push Notification

Android &-8211; RenderScript

Android &-8211; RSS Reader

Android &-8211; Screen Cast

Android &-8211; SDK Manager

Android &-8211; Sensors

Android &-8211; Session Management

Android &-8211; Shared Preferences

Android &-8211; SIP Protocol

Android &-8211; Spelling Checker

Android &-8211; SQLite Database

Android &-8211; Support Library

Android &-8211; Testing

Android &-8211; Text to Speech

Android &-8211; TextureView

Android &-8211; Twitter Integration

Android &-8211; UI Design

Android &-8211; UI Patterns

Android &-8211; UI Testing

Android &-8211; WebView Layout

Android &-8211; Wi-Fi

Android &-8211; Widgets

Android &-8211; XML Parsers

Android &-8211; Questions and Answers

Android &-8211; Useful Resources

Android &-8211; Discussion

UPSC IAS Exams Notes

Developer&-8217;s Best Practices

Questions and Answers

Effective Resume Writing

HR Interview Questions

Computer Glossary

Who is Who

Android Questions and Answers

Android Questions and Answers &-8211; this Article or News was published on this date:2019-05-13 19:48:38 kindly share it with friends if you find it helpful

Android Questions and Answers


Advertisements


Android Questions and Answers has been designed with a special intention of helping students and professionals preparing for various Certification Exams and Job Interviews. This section provides a useful collection of sample Interview Questions and Multiple Choice Questions (MCQs) and their answers with appropriate explanations.

Questions and Answers

SN Question/Answers Type
1 Android Interview Questions

This section provides a huge collection of Android Interview Questions with their answers hidden in a box to challenge you to have a go at them before discovering the correct answer.

2 Android Online Quiz

This section provides a great collection of Android Multiple Choice Questions (MCQs) on a single page along with their correct answers and explanation. If you select the right option, it turns green; else red.

3 Android Online Test

If you are preparing to appear for a Java and Android Framework related certification exam, then this section is a must for you. This section simulates a real online test along with a given timer which challenges you to complete the test within a given time-frame. Finally you can check your overall test score and how you fared among millions of other candidates who attended this online test.

4 Android Mock Test

This section provides various mock tests that you can download at your local machine and solve offline. Every mock test is supplied with a mock test key to let you verify the final score and grade yourself.



Advertisements

Android Video Tutorials

Android &-8211; Home

Android &-8211; Overview

Android &-8211; Environment Setup

Android &-8211; Architecture

Android &-8211; Application Components

Android &-8211; Hello World Example

Android &-8211; Resources

Android &-8211; Activities

Android &-8211; Services

Android &-8211; Broadcast Receivers

Android &-8211; Content Providers

Android &-8211; Fragments

Android &-8211; Intents/Filters

Android &-8211; UI Layouts

Android &-8211; UI Controls

Android &-8211; Event Handling

Android &-8211; Styles and Themes

Android &-8211; Custom Components

Android &-8211; Drag and Drop

Android &-8211; Notifications

Location Based Services

Android &-8211; Sending Email

Android &-8211; Sending SMS

Android &-8211; Phone Calls

Publishing Android Application

Android &-8211; Alert Dialoges

Android &-8211; Animations

Android &-8211; Audio Capture

Android &-8211; AudioManager

Android &-8211; Auto Complete

Android &-8211; Best Practices

Android &-8211; Bluetooth

Android &-8211; Camera

Android &-8211; Clipboard

Android &-8211; Custom Fonts

Android &-8211; Data Backup

Android &-8211; Developer Tools

Android &-8211; Emulator

Android &-8211; Facebook Integration

Android &-8211; Gestures

Android &-8211; Google Maps

Android &-8211; Image Effects

Android &-8211; ImageSwitcher

Android &-8211; Internal Storage

Android &-8211; JetPlayer

Android &-8211; JSON Parser

Android &-8211; Linkedin Integration

Android &-8211; Loading Spinner

Android &-8211; Localization

Android &-8211; Login Screen

Android &-8211; MediaPlayer

Android &-8211; Multitouch

Android &-8211; Navigation

Android &-8211; Network Connection

Android &-8211; NFC Guide

Android &-8211; PHP/MySQL

Android &-8211; Progress Circle

Android &-8211; ProgressBar

Android &-8211; Push Notification

Android &-8211; RenderScript

Android &-8211; RSS Reader

Android &-8211; Screen Cast

Android &-8211; SDK Manager

Android &-8211; Sensors

Android &-8211; Session Management

Android &-8211; Shared Preferences

Android &-8211; SIP Protocol

Android &-8211; Spelling Checker

Android &-8211; SQLite Database

Android &-8211; Support Library

Android &-8211; Testing

Android &-8211; Text to Speech

Android &-8211; TextureView

Android &-8211; Twitter Integration

Android &-8211; UI Design

Android &-8211; UI Patterns

Android &-8211; UI Testing

Android &-8211; WebView Layout

Android &-8211; Wi-Fi

Android &-8211; Widgets

Android &-8211; XML Parsers

Android &-8211; Questions and Answers

Android &-8211; Useful Resources

Android &-8211; Discussion

UPSC IAS Exams Notes

Developer&-8217;s Best Practices

Questions and Answers

Effective Resume Writing

HR Interview Questions

Computer Glossary

Who is Who

Android – XML Parser

Android &-8211; XML Parser &-8211; this Article or News was published on this date:2019-05-13 19:48:37 kindly share it with friends if you find it helpful

Android &-8211; XML Parser


Advertisements


XML stands for Extensible Mark-up Language.XML is a very popular format and commonly used for sharing data on the internet. This chapter explains how to parse the XML file and extract necessary information from it.

Android provides three types of XML parsers which are DOM,SAX and XMLPullParser. Among all of them android recommend XMLPullParser because it is efficient and easy to use. So we are going to use XMLPullParser for parsing XML.

The first step is to identify the fields in the XML data in which you are interested in. For example. In the XML given below we interested in getting temperature only.

?xml version="1.0"?>
current>
   
   city id="2643743" name="London">
      coord lon="-0.12574" lat="51.50853"/>
      country>GB/country>
      sun rise="2013-10-08T06:13:56" set="2013-10-08T17:21:45"/>
   /city>
   
   temperature value="289.54" min="289.15" max="290.15" unit="kelvin"/>
   humidity value="77" unit="%"/>
   pressure value="1025" unit="hPa"/>
/current>

XML &-8211; Elements

An xml file consist of many components. Here is the table defining the components of an XML file and their description.

Sr.No Component & description
1

Prolog

An XML file starts with a prolog. The first line that contains the information about a file is prolog

2

Events

An XML file has many events. Event could be like this. Document starts , Document ends, Tag start , Tag end and Text e.t.c

3

Text

Apart from tags and events, and xml file also contains simple text. Such as GB is a text in the country tag.

4

Attributes

Attributes are the additional properties of a tag such as value e.t.c

XML &-8211; Parsing

In the next step, we will create XMLPullParser object , but in order to create that we will first create XmlPullParserFactory object and then call its newPullParser() method to create XMLPullParser. Its syntax is given below −

private XmlPullParserFactory xmlFactoryObject = XmlPullParserFactory.newInstance();
private XmlPullParser myparser = xmlFactoryObject.newPullParser();

The next step involves specifying the file for XmlPullParser that contains XML. It could be a file or could be a Stream. In our case it is a stream.Its syntax is given below −

myparser.setInput(stream, null);

The last step is to parse the XML. An XML file consist of events, Name, Text, AttributesValue e.t.c. So XMLPullParser has a separate function for parsing each of the component of XML file. Its syntax is given below −

int event = myParser.getEventType();
while (event != XmlPullParser.END_DOCUMENT)  {
   String name=myParser.getName();
   switch (event){
      case XmlPullParser.START_TAG:
      break;
      
      case XmlPullParser.END_TAG:
      if(name.equals("temperature")){
         temperature = myParser.getAttributeValue(null,"value");
      }
      break;
   }		 
   event = myParser.next(); 					
}

The method getEventType returns the type of event that happens. e.g: Document start , tag start e.t.c. The method getName returns the name of the tag and since we are only interested in temperature , so we just check in conditional statement that if we got a temperature tag , we call the method getAttributeValue to return us the value of temperature tag.

Apart from the these methods, there are other methods provided by this class for better parsing XML files. These methods are listed below −

Sr.No Method & description
1

getAttributeCount()

This method just Returns the number of attributes of the current start tag

2

getAttributeName(int index)

This method returns the name of the attribute specified by the index value

3

getColumnNumber()

This method returns the Returns the current column number, starting from 0.

4

getDepth()

This method returns Returns the current depth of the element.

5

getLineNumber()

Returns the current line number, starting from 1.

6

getNamespace()

This method returns the name space URI of the current element.

7

getPrefix()

This method returns the prefix of the current element

8

getName()

This method returns the name of the tag

9

getText()

This method returns the text for that particular element

10

isWhitespace()

This method checks whether the current TEXT event contains only whitespace characters.

Example

Here is an example demonstrating the use of XML DOM Parser. It creates a basic application that allows you to parse XML.

To experiment with this example, you can run this on an actual device or in an emulator.

Steps Description
1 You will use Android studio to create an Android application under a package com.example.sairamkrishna.myapplication.
2 Modify src/MainActivity.java file to add necessary code.
3 Modify the res/layout/activity_main to add respective XML components
4 Create a new XML file under Assets Folder/file.xml
5 Modify AndroidManifest.xml to add necessary internet permission
6 Run the application and choose a running android device and install the application on it and verify the results

Following is the content of the modified main activity file MainActivity.java.

package com.example.sairamkrishna.myapplication;

import java.io.InputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends Activity {
   TextView tv1;

   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      tv1=(TextView)findViewById(R.id.textView1);
		
      try {
         InputStream is = getAssets().open("file.xml");

         DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
         DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
         Document doc = dBuilder.parse(is);

         Element element=doc.getDocumentElement();
         element.normalize();

         NodeList nList = doc.getElementsByTagName("employee");
			
         for (int i=0; inList.getLength(); i++) {

            Node node = nList.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE) {
               Element element2 = (Element) node;
               tv1.setText(tv1.getText()+"nName : " + getValue("name", element2)+"n");
               tv1.setText(tv1.getText()+"Surname : " + getValue("surname", element2)+"n");
               tv1.setText(tv1.getText()+"-----------------------");
            }
         }
			
      } catch (Exception e) {e.printStackTrace();}

   }
	
   private static String getValue(String tag, Element element) {
      NodeList nodeList = element.getElementsByTagName(tag).item(0).getChildNodes();
      Node node = nodeList.item(0);
      return node.getNodeValue();
   }

}

Following is the content of Assets/file.xml.

?xml version="1.0"?>
records>
   employee>
      name>Sairamkrishna/name>
      surname>Mammahe/surname>
      salary>50000/salary>
   /employee>
	
   employee>
      name>Gopal /name>
      surname>Varma/surname>
      salary>60000/salary>
   /employee>
	
   employee>
      name>Raja/name>
      surname>Hr/surname>
      salary>70000/salary>
   /employee>
	
/records>

Following is the modified content of the xml res/layout/activity_main.xml.

?xml version="1.0" encoding="utf-8"?>
RelativeLayout xmlns: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">

   TextView
      android:id="@+id/textView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" />
/RelativeLayout>

Following is the content of AndroidManifest.xml file.

?xml version="1.0" encoding="utf-8"?>
manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example.sairamkrishna.myapplication" >
   application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" >
      
      activity
         android:name=".MainActivity"
         android:label="@string/app_name" >
         
         intent-filter>
            action android:name="android.intent.action.MAIN" />
            category android:name="android.intent.category.LAUNCHER" />
         /intent-filter>
      
      /activity>
   
   /application>
/manifest>

Let&-8217;s try to run our application we just modified. I assume you had created your AVD while doing environment setup. To run the app from Android studio, open one of your project&-8217;s activity files and click Run Eclipse Run Icon icon from the toolbar. Android studio installs the app on your AVD and starts it and if everything is fine with your setup and application, it will display following Emulator window −

Anroid XML Parser Tutorial



Advertisements

Android Video Tutorials

Android &-8211; Home

Android &-8211; Overview

Android &-8211; Environment Setup

Android &-8211; Architecture

Android &-8211; Application Components

Android &-8211; Hello World Example

Android &-8211; Resources

Android &-8211; Activities

Android &-8211; Services

Android &-8211; Broadcast Receivers

Android &-8211; Content Providers

Android &-8211; Fragments

Android &-8211; Intents/Filters

Android &-8211; UI Layouts

Android &-8211; UI Controls

Android &-8211; Event Handling

Android &-8211; Styles and Themes

Android &-8211; Custom Components

Android &-8211; Drag and Drop

Android &-8211; Notifications

Location Based Services

Android &-8211; Sending Email

Android &-8211; Sending SMS

Android &-8211; Phone Calls

Publishing Android Application

Android &-8211; Alert Dialoges

Android &-8211; Animations

Android &-8211; Audio Capture

Android &-8211; AudioManager

Android &-8211; Auto Complete

Android &-8211; Best Practices

Android &-8211; Bluetooth

Android &-8211; Camera

Android &-8211; Clipboard

Android &-8211; Custom Fonts

Android &-8211; Data Backup

Android &-8211; Developer Tools

Android &-8211; Emulator

Android &-8211; Facebook Integration

Android &-8211; Gestures

Android &-8211; Google Maps

Android &-8211; Image Effects

Android &-8211; ImageSwitcher

Android &-8211; Internal Storage

Android &-8211; JetPlayer

Android &-8211; JSON Parser

Android &-8211; Linkedin Integration

Android &-8211; Loading Spinner

Android &-8211; Localization

Android &-8211; Login Screen

Android &-8211; MediaPlayer

Android &-8211; Multitouch

Android &-8211; Navigation

Android &-8211; Network Connection

Android &-8211; NFC Guide

Android &-8211; PHP/MySQL

Android &-8211; Progress Circle

Android &-8211; ProgressBar

Android &-8211; Push Notification

Android &-8211; RenderScript

Android &-8211; RSS Reader

Android &-8211; Screen Cast

Android &-8211; SDK Manager

Android &-8211; Sensors

Android &-8211; Session Management

Android &-8211; Shared Preferences

Android &-8211; SIP Protocol

Android &-8211; Spelling Checker

Android &-8211; SQLite Database

Android &-8211; Support Library

Android &-8211; Testing

Android &-8211; Text to Speech

Android &-8211; TextureView

Android &-8211; Twitter Integration

Android &-8211; UI Design

Android &-8211; UI Patterns

Android &-8211; UI Testing

Android &-8211; WebView Layout

Android &-8211; Wi-Fi

Android &-8211; Widgets

Android &-8211; XML Parsers

Android &-8211; Questions and Answers

Android &-8211; Useful Resources

Android &-8211; Discussion

UPSC IAS Exams Notes

Developer&-8217;s Best Practices

Questions and Answers

Effective Resume Writing

HR Interview Questions

Computer Glossary

Who is Who

Android – Widgets

Android &-8211; Widgets &-8211; this Article or News was published on this date:2019-05-13 19:48:36 kindly share it with friends if you find it helpful

Android &-8211; Widgets


Advertisements


A 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 home screen 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 &-8211; XML file

In order to create an application widget, first thing you need is AppWidgetProviderInfo object, which you will define in a separate 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>

Widget &-8211; Layout file

Now you have to define the layout of your widget in your default XML file. You can drag components to generate auto xml.

Widget &-8211; Java file

After defining layout, now create a new JAVA file or use existing one, and extend it with AppWidgetProvider class and override its update method as follows.

In the update method, you have to define the object of two classes which are PendingIntent and RemoteViews. Its syntax is −

PendingIntent pending = PendingIntent.getActivity(context, 0, intent, 0);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.activity_main);

In the end you have to call an update method updateAppWidget() of the AppWidgetManager class. Its syntax is −

appWidgetManager.updateAppWidget(currentWidgetId,views);		

A part from the updateAppWidget method, there are other methods defined in this class to manipulate widgets. They are as follows −

Sr.No Method & Description
1

onDeleted(Context context, int[] appWidgetIds)

This is called when an instance of AppWidgetProvider is deleted.

2

onDisabled(Context context)

This is called when the last instance of AppWidgetProvider is deleted

3

onEnabled(Context context)

This is called when an instance of AppWidgetProvider is created.

4

onReceive(Context context, Intent intent)

It is used to dispatch calls to the various methods of the class

Widget &-8211; Manifest file

You also have to declare the AppWidgetProvider class in your manifest file as follows:

receiver android:name="ExampleAppWidgetProvider" >
   
   intent-filter>
      action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
   /intent-filter>
   
   meta-data android:name="android.appwidget.provider"
      android:resource="@xml/example_appwidget_info" />
/receiver>

Example

Here is an example demonstrating the use of application Widget. It creates a basic widget applications that will open this current website in the browser.

To experiment with this example, you need to run this on an actual device on which internet is running.

Steps Description
1 You will use Android studio to create an Android application under a package com.example.sairamkrishna.myapplication.
2 Modify src/MainActivity.java file to add widget code.
3 Modify the res/layout/activity_main to add respective XML components
4 Create a new folder and xml file under res/xml/mywidget.xml to add respective XML components
5 Modify the AndroidManifest.xml to add the necessary permissions
6 Run the application and choose a running android device and install the application on it and verify the results.

Following is the content of the modified MainActivity.java.

package com.example.sairamkrishna.myapplication;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.widget.RemoteViews;
import android.widget.Toast;

public class MainActivity extends AppWidgetProvider{
   public void onUpdate(Context context, AppWidgetManager appWidgetManager,int[] appWidgetIds) {
      for(int i=0; iappWidgetIds.length; i++){
         int currentWidgetId = appWidgetIds[i];
         String url = "http://webforums.club";
         
         Intent intent = new Intent(Intent.ACTION_VIEW);
         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         intent.setData(Uri.parse(url));
         
         PendingIntent pending = PendingIntent.getActivity(context, 0,intent, 0);
         RemoteViews views = new RemoteViews(context.getPackageName(),R.layout.activity_main);
         
         views.setOnClickPendingIntent(R.id.button, pending);
         appWidgetManager.updateAppWidget(currentWidgetId,views);
         Toast.makeText(context, "widget added", Toast.LENGTH_SHORT).show();
      }
   }
}

Following is the modified content of the xml res/layout/activity_main.xml.

?xml version="1.0" encoding="utf-8"?>
RelativeLayout xmlns: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:paddingLeft="@dimen/activity_horizontal_margin"
   android:paddingRight="@dimen/activity_horizontal_margin"
   android:paddingTop="@dimen/activity_vertical_margin"
   android:paddingBottom="@dimen/activity_vertical_margin"
   tools:context=".MainActivity"
   android:transitionGroup="true">
   
   TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Tutorials point"
      android:id="@+id/textView"
      android:layout_centerHorizontal="true"
      android:textColor="-ff3412ff"
      android:textSize="35dp" />
      
   Button
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Widget"
      android:id="@+id/button"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="61dp"
      android:layout_below="@+id/textView" />

/RelativeLayout>

Following is the content of the res/xml/mywidget.xml.

?xml version="1.0" encoding="utf-8"?>
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>

Following is the content of the res/values/string.xml.

resources>
   string name="app_name">My Application/string>
/resources>

Following is the content of AndroidManifest.xml file.

?xml version="1.0" encoding="utf-8"?>
manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example.sairamkrishna.myapplication" >
   
   application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" >
      receiver android:name=".MainActivity">
      
      intent-filter>
         action android:name="android.appwidget.action.APPWIDGET_UPDATE">/action>
      /intent-filter>
      
      meta-data android:name="android.appwidget.provider"
         android:resource="@xml/mywidget">/meta-data>
      
      /receiver>
   
   /application>
/manifest>

Let&-8217;s try to run your application. I assume you have connected your actual Android Mobile device with your computer. To run the app from Android studio, open one of your project&-8217;s activity files and click Run Eclipse Run Icon icon from the tool bar. Before starting your application, Android studio will display following window to select an option where you want to run your Android application.

Anroid Widget Tutorial

Select your mobile device as an option and then check your mobile device which will display your default screen −

Anroid Widget Tutorial

Go to your widget section and add your created widget to the desktop or home screen. It would look something like this −

Anroid Widget Tutorial

Now just tap on the widget button that appears, to launch the browser. But before that please make sure that you are connected to the internet. After pressing the button , the following screen would appear −

Anroid Widget Tutorial

Note. By just changing the url in the java file, your widget will open your desired website in the browser.



Advertisements

Android Video Tutorials

Android &-8211; Home

Android &-8211; Overview

Android &-8211; Environment Setup

Android &-8211; Architecture

Android &-8211; Application Components

Android &-8211; Hello World Example

Android &-8211; Resources

Android &-8211; Activities

Android &-8211; Services

Android &-8211; Broadcast Receivers

Android &-8211; Content Providers

Android &-8211; Fragments

Android &-8211; Intents/Filters

Android &-8211; UI Layouts

Android &-8211; UI Controls

Android &-8211; Event Handling

Android &-8211; Styles and Themes

Android &-8211; Custom Components

Android &-8211; Drag and Drop

Android &-8211; Notifications

Location Based Services

Android &-8211; Sending Email

Android &-8211; Sending SMS

Android &-8211; Phone Calls

Publishing Android Application

Android &-8211; Alert Dialoges

Android &-8211; Animations

Android &-8211; Audio Capture

Android &-8211; AudioManager

Android &-8211; Auto Complete

Android &-8211; Best Practices

Android &-8211; Bluetooth

Android &-8211; Camera

Android &-8211; Clipboard

Android &-8211; Custom Fonts

Android &-8211; Data Backup

Android &-8211; Developer Tools

Android &-8211; Emulator

Android &-8211; Facebook Integration

Android &-8211; Gestures

Android &-8211; Google Maps

Android &-8211; Image Effects

Android &-8211; ImageSwitcher

Android &-8211; Internal Storage

Android &-8211; JetPlayer

Android &-8211; JSON Parser

Android &-8211; Linkedin Integration

Android &-8211; Loading Spinner

Android &-8211; Localization

Android &-8211; Login Screen

Android &-8211; MediaPlayer

Android &-8211; Multitouch

Android &-8211; Navigation

Android &-8211; Network Connection

Android &-8211; NFC Guide

Android &-8211; PHP/MySQL

Android &-8211; Progress Circle

Android &-8211; ProgressBar

Android &-8211; Push Notification

Android &-8211; RenderScript

Android &-8211; RSS Reader

Android &-8211; Screen Cast

Android &-8211; SDK Manager

Android &-8211; Sensors

Android &-8211; Session Management

Android &-8211; Shared Preferences

Android &-8211; SIP Protocol

Android &-8211; Spelling Checker

Android &-8211; SQLite Database

Android &-8211; Support Library

Android &-8211; Testing

Android &-8211; Text to Speech

Android &-8211; TextureView

Android &-8211; Twitter Integration

Android &-8211; UI Design

Android &-8211; UI Patterns

Android &-8211; UI Testing

Android &-8211; WebView Layout

Android &-8211; Wi-Fi

Android &-8211; Widgets

Android &-8211; XML Parsers

Android &-8211; Questions and Answers

Android &-8211; Useful Resources

Android &-8211; Discussion

UPSC IAS Exams Notes

Developer&-8217;s Best Practices

Questions and Answers

Effective Resume Writing

HR Interview Questions

Computer Glossary

Who is Who

Android – Wi-Fi

Android &-8211; Wi-Fi &-8211; this Article or News was published on this date:2019-05-13 19:48:34 kindly share it with friends if you find it helpful

Android &-8211; Wi-Fi


Advertisements


Android allows applications to access to view the access the state of the wireless 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&-8217;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); 

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 receiver class object. Its syntax is given below −

class WifiScanReceiver extends BroadcastReceiver {
   public void onReceive(Context c, Intent intent) {
   }
}

WifiScanReceiver wifiReciever = new WifiScanReceiver();
registerReceiver(wifiReciever, new IntentFilter(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 −

ListScanResult> 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.No Method & Description
1

addNetwork(WifiConfiguration config)

This method add a new network description to the set of configured networks.

2

createWifiLock(String tag)

This method creates a new WifiLock.

3

disconnect()

This method disassociate from the currently active access point.

4

enableNetwork(int netId, boolean disableOthers)

This method allow a previously configured network to be associated with.

5

getWifiState()

This method gets the Wi-Fi enabled state

6

isWifiEnabled()

This method return whether Wi-Fi is enabled or disabled.

7

setWifiEnabled(boolean enabled)

This method enable or disable Wi-Fi.

8

updateNetwork(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 open your wifi and close your wifi

To experiment with this example, you need to run this on an actual device on which wifi is turned on.

Steps Description
1 You will use Android studio to create an Android application under a package com.example.sairamkrishna.myapplication.
2 Modify src/MainActivity.java file to add WebView code.
3 Modify the res/layout/activity_main to add respective XML components
4 Modify the AndroidManifest.xml to add the necessary permissions
5 Run the application and choose a running android device and install the application on it and verify the results.

Following is the content of the modified main activity file src/MainActivity.java.

package com.example.sairamkrishna.myapplication;

import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
   Button enableButton,disableButton;
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);

      enableButton=(Button)findViewById(R.id.button1);
      disableButton=(Button)findViewById(R.id.button2);

      enableButton.setOnClickListener(new OnClickListener(){
         public void onClick(View v){
            WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
            wifi.setWifiEnabled(true);
         }
      });
		
      disableButton.setOnClickListener(new OnClickListener(){
         public void onClick(View v){
            WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
            wifi.setWifiEnabled(false);
         }
      });
   }
}

Following is the modified content of the xml res/layout/activity_main.xml.

?xml version="1.0" encoding="utf-8"?>
RelativeLayout xmlns: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:paddingLeft="@dimen/activity_horizontal_margin"
   android:paddingRight="@dimen/activity_horizontal_margin"
   android:paddingTop="@dimen/activity_vertical_margin"
   android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
	
   ImageView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/imageView"
      android:src="@drawable/abc"
      android:layout_alignParentTop="true"
      android:layout_centerHorizontal="true" />
		
   Button
      android:id="@+id/button1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginLeft="76dp"
      android:text="Enable Wifi"
      android:layout_centerVertical="true"
      android:layout_alignEnd="@+id/imageView" />

   Button
      android:id="@+id/button2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Disable Wifi"
      android:layout_marginBottom="93dp"
      android:layout_alignParentBottom="true"
      android:layout_alignStart="@+id/imageView" />

/RelativeLayout>

Following is the content of AndroidManifest.xml file.

?xml version="1.0" encoding="utf-8"?>
manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example.sairamkrishna.myapplication" >
   uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
   uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
   
   application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" >
      
      activity
         android:name=".MainActivity"
         android:label="@string/app_name" >
         
         intent-filter>
            action android:name="android.intent.action.MAIN" />
            category android:name="android.intent.category.LAUNCHER" />
         /intent-filter>
         
      /activity>
      
   /application>
/manifest>

Let&-8217;s try to run your application. I assume you have connected your actual Android Mobile device with your computer. To run the app from Android studio, open one of your project&-8217;s activity files and click Run Eclipse Run Icon icon from the toolbar. Before starting your application, Android studio 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 It will shows the following image−

Anroid Wi-Fi Tutorial

Now click on disable wifi button.then the sample output should be like this −

android_wifi_tutorials



Advertisements

Android Video Tutorials

Android &-8211; Home

Android &-8211; Overview

Android &-8211; Environment Setup

Android &-8211; Architecture

Android &-8211; Application Components

Android &-8211; Hello World Example

Android &-8211; Resources

Android &-8211; Activities

Android &-8211; Services

Android &-8211; Broadcast Receivers

Android &-8211; Content Providers

Android &-8211; Fragments

Android &-8211; Intents/Filters

Android &-8211; UI Layouts

Android &-8211; UI Controls

Android &-8211; Event Handling

Android &-8211; Styles and Themes

Android &-8211; Custom Components

Android &-8211; Drag and Drop

Android &-8211; Notifications

Location Based Services

Android &-8211; Sending Email

Android &-8211; Sending SMS

Android &-8211; Phone Calls

Publishing Android Application

Android &-8211; Alert Dialoges

Android &-8211; Animations

Android &-8211; Audio Capture

Android &-8211; AudioManager

Android &-8211; Auto Complete

Android &-8211; Best Practices

Android &-8211; Bluetooth

Android &-8211; Camera

Android &-8211; Clipboard

Android &-8211; Custom Fonts

Android &-8211; Data Backup

Android &-8211; Developer Tools

Android &-8211; Emulator

Android &-8211; Facebook Integration

Android &-8211; Gestures

Android &-8211; Google Maps

Android &-8211; Image Effects

Android &-8211; ImageSwitcher

Android &-8211; Internal Storage

Android &-8211; JetPlayer

Android &-8211; JSON Parser

Android &-8211; Linkedin Integration

Android &-8211; Loading Spinner

Android &-8211; Localization

Android &-8211; Login Screen

Android &-8211; MediaPlayer

Android &-8211; Multitouch

Android &-8211; Navigation

Android &-8211; Network Connection

Android &-8211; NFC Guide

Android &-8211; PHP/MySQL

Android &-8211; Progress Circle

Android &-8211; ProgressBar

Android &-8211; Push Notification

Android &-8211; RenderScript

Android &-8211; RSS Reader

Android &-8211; Screen Cast

Android &-8211; SDK Manager

Android &-8211; Sensors

Android &-8211; Session Management

Android &-8211; Shared Preferences

Android &-8211; SIP Protocol

Android &-8211; Spelling Checker

Android &-8211; SQLite Database

Android &-8211; Support Library

Android &-8211; Testing

Android &-8211; Text to Speech

Android &-8211; TextureView

Android &-8211; Twitter Integration

Android &-8211; UI Design

Android &-8211; UI Patterns

Android &-8211; UI Testing

Android &-8211; WebView Layout

Android &-8211; Wi-Fi

Android &-8211; Widgets

Android &-8211; XML Parsers

Android &-8211; Questions and Answers

Android &-8211; Useful Resources

Android &-8211; Discussion

UPSC IAS Exams Notes

Developer&-8217;s Best Practices

Questions and Answers

Effective Resume Writing

HR Interview Questions

Computer Glossary

Who is Who