Android Lab Manual
Android Lab Manual
THEORY:
What is Android?
Android is an open source and Linux-based Operating System for mobile devices
such as smartphones and tablet computers. Android was developed by the Open
Handset Alliance, led by Google, and other companies.
Android offers a unified approach to application development for mobile devices
which means developers need only develop for Android, and their applications
should be able to run on different devices powered by Android.
The first beta version of the Android Software Development Kit (SDK) was released
by Google in 2007 where as the first commercial version, Android 1.0, was released
in September 2008.
On June 27, 2012, at the Google I/O conference, Google announced the next
Android version, 4.1 Jelly Bean. Jelly Bean is an incremental update, with the
primary aim of improving the user interface, both in terms of functionality and
performance.
The source code for Android is available under free and open source software
licenses. Google publishes most of the code under the Apache License version 2.0
and the rest, Linux kernel changes, under the GNU General Public License version
2.
Why Android ?
Features of Android
Android is a powerful operating system competing with Apple 4GS and supports
great features. Few of them are listed below:
Feature Description
Media support H.263, H.264, MPEG-4 SP, AMR, AMR-WB, AAC, HE-AAC,
AAC 5.1, MP3, MIDI, Ogg Vorbis, WAV, JPEG, PNG, GIF, and
BMP
Multi-tasking User can jump from one task to another and same time
various application can run simultaneously.
Resizable widgets Widgets are resizable, so users can expand them to show
more content or shrink them to save space
Wi-Fi Direct A technology that lets apps discover and pair directly, over
a high-bandwidth peer-to-peer connection.
Android Applications
Android applications are usually developed in the Java language using the Android
Software Development Kit.
Once developed, Android applications can be packaged easily and sold out either
through a store such as Google Play,SlideME,Opera Mobile Store,Mobango,F-
droid and the Amazon Appstore.
Android powers hundreds of millions of mobile devices in more than 190 countries
around the world. It's the largest installed base of any mobile platform and
growing fast. Every day more than 1 million new Android devices are activated
worldwide.
Categories of Android applications
There are many android applications in the market. The top categories are:
Installation of android:
THEORY:
Create a Project
1. Step 1: Create a New Project
2. Step 2: Select Form Factors and API Level
3. Step 3: Add an Activity
4. Step 4: Configure Your Activity
5. Step 5: Develop Your App
A project in Android Studio contains one or more modules that keep your code
organized into discrete units of functionality. Android Studio makes it easy to create
Android apps for various form factors, such as phone, tablet, TV, Wear, and Google
Glass. The New Project wizard lets you choose the form factors for your app and
populates the project structure with everything you need to get started.
If you didn't have a project opened, Android Studio shows the Welcome screen. To
create a new project, click Start a New Android Studio project.
If you had a project opened, Android Studio shows the development environment.
To create a new project, click File > New > New Project.
The next window lets you configure the name of your app, the package name, and
the location of your project.
The Android Platform Distribution window shows the distribution of mobile devices
running each version of Android, as shown in figure 2. Click on an API level to see a
list of features introduced in the corresponding version of Android. This helps you
choose the minimum API Level that has all the features that your apps needs, so
you can reach as many devices as possible. Then click OK.
Figure 3. The Target Android Devices screen.
Then, on the Target Android Devices Window, once you've selected your form
factors and API versions, click Next.
The next screen lets you select an activity type to add to your app, as shown in
figure 4. This screen displays a different set of activities for each of the form factors
you selected earlier.
Note: If you choose "Add No Activity", click Finish to create the project.
Step 4: Configure Your Activity
The next screen lets you configure the activity to add to your app, as shown in figure
5.
Enter the activity name, the layout name, and the activity title. Then click Finish.
Android Studio creates the default structure for your project and opens the
development environment. If your app supports more than one form factor,
Android Studio creates a module folder with complete source files for each of them
as shown in figure 6.
Figure 6. Project structure for a newly created app.
You can run an app from an Android Studio project. Or, you can run an app that's
been installed on the emulator as you would run any app on a device.
The No USB devices or running emulators detected warning means that you
don’t currently have any emulators running, or any detected hardware devices
connected to your computer. If you don’t have hardware devices connected to
your computer, or any emulators running, you can ignore it.
Some errors you must fix before you can continue, such as certain Hardware
Accelerated Execution Manager (Intel® HAXM) errors.
The emulator device stores the installed app so you can run it again, if needed.
You need to uninstall an app to remove it. If you run the project again on the
same emulator, it replaces the app with the new version.
While the emulator is running, you can run Android Studio projects and choose
the emulator as the target device. You can also drag one or more APKs onto the
emulator to install them, and then run them.
AIM: a.i. Edit the manifest and change min sdk and target sdk of application.
a.ii. Add main activity entries in manifest.
a.iii. Add second activity entries in manifest.
a.iv. Add Entries for Broadcast receivers.
a.v. Add uses permissions for camera
a.i. To Change API SDK Level AND target level In Android Studio:
Basically, API level means the Android version. This defines for which version
you are targeting your application and what is going to be the minimum level of
android version in your application will run. For setting Minimum level and
Maximum level android studio provides two terminologies.
minSdkVersion means minimum Android OS version that will support your app
and targetSdkVersion means the version for which you are actually developing
your application. Your app will be compatible with all the version of android
which are falling between minimum level SDK and target SDK.
You can check the name of version too in the drop down list while selecting the
API level that makes the selection more clearer for anyone. Because sometimes
remembering numbers is bit messy.
Step 4: Select both the versions and Click OK.
applicationId "com.AbhiAndroid.Android.myProject"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
Step 3: Click on Sync Now and You are ready to go.
Note: If you are choosing the First Approach then you need not to make changes
in Gradle. It will automatically update the gradle.
PROJECT NO. 04
Project to show the usage of button.
Theory:
MainActivity.java
package com.example.dell.button;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
----------------------------------------------------------------------------
PROJECT NO. 05
05. Project to add two numbers:
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
t1.setText(Integer.toString(sum));
}
}
OUTPUT:
-------------------------------------------------------------------------------------------------------------
-----------------------------
PROJECT NO.06
Aim: project to show usage of radio button
Theory:
package com.example.dell.radiobutton;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
Toast.makeText(MainActivity.this,radio_b.getText().toString(),Toast.LENGTH_SHO
RT).show();;
}
}
);
}
}
OUTPUT:
PROJECT NO. 07
07. Create an application for Checkbox.
package com.example.dell.checkboxfoodexample;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
public class MainActivity extends AppCompatActivity {
CheckBox pizza,coffe,burger;
Button buttonOrder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButtonClick();
}
public void addListenerOnButtonClick(){
//Getting instance of CheckBoxes and Button from the activty_main.xml file
pizza=(CheckBox)findViewById(R.id.checkBox1);
coffe=(CheckBox)findViewById(R.id.checkBox2);
burger=(CheckBox)findViewById(R.id.checkBox3);
buttonOrder=(Button)findViewById(R.id.button1);
@Override
public void onClick(View view) {
int totalamount=0;
StringBuilder result=new StringBuilder();
result.append("Selected Items:");
if(pizza.isChecked()){
result.append("\nPizza 100Rs");
totalamount+=100;
}
if(coffe.isChecked()){
result.append("\nCoffe 50Rs");
totalamount+=50;
}
if(burger.isChecked()){
result.append("\nBurger 120Rs");
totalamount+=120;
}
result.append("\nTotal: "+totalamount+"Rs");
//Displaying the message on the toast
Toast.makeText(getApplicationContext(), result.toString(),
Toast.LENGTH_LONG).show();
}
});
}
OUTPUT
PROJECT NO. 08
08. Create an application for alert box.
package com.example.dell.alert;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
OnButtonClicklistener();
}
);
OUTPUT
09. Create an application for making a phone call.
package com.example.dell.phonecall;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.net.Uri;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
@Override
public void onClick(View arg0) {
String number=edittext1.getText().toString();
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+number));
startActivity(callIntent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
OUTPUT
PROJECT NO. 10
10. Create an application for sending sms.
package com.example.sendsms;
import android.os.Bundle;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.telephony.SmsManager;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
EditText mobileno,message;
Button sendsms;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mobileno=(EditText)findViewById(R.id.editText1);
message=(EditText)findViewById(R.id.editText2);
sendsms=(Button)findViewById(R.id.button1);
@Override
public void onClick(View arg0) {
String no=mobileno.getText().toString();
String msg=message.getText().toString();
//Getting intent and PendingIntent instance
Intent intent=new Intent(getApplicationContext(),MainActivity.class);
PendingIntent pi=PendingIntent.getActivity(getApplicationContext(), 0, inte
nt,0);
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
OUTPUT:
PROJECT NO 11
11 . Make a project to open any webpage by inputting Url.
package com.example.dell.url;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
]import android.widget.Button;
import android.widget.EditText;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
photoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent cameraIntent = new
Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
}
}
OUTPUT:
********