0% found this document useful (0 votes)
23 views

Android Lab Manual

Android studio laboratory manual with solution college

Uploaded by

Akash
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Android Lab Manual

Android studio laboratory manual with solution college

Uploaded by

Akash
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

PRACTICAL NO.

AIM: Basic definition, features, application, and categories of Android.

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

Beautiful UI Android OS basic screen provides a beautiful and intuitive


user interface.

Connectivity GSM/EDGE, IDEN, CDMA, EV-DO, UMTS, Bluetooth, Wi-Fi,


LTE, NFC and WiMAX.

Storage SQLite, a lightweight relational database, is used for data


storage purposes.

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

Messaging SMS and MMS


Web browser Based on the open-source WebKit layout engine, coupled
with Chrome's V8 JavaScript engine supporting HTML5
and CSS3.

Multi-touch Android has native support for multi-touch which was


initially made available in handsets such as the HTC Hero.

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

Multi-Language Supports single direction and bi-directional text.

GCM Google Cloud Messaging (GCM) is a service that lets


developers send short message data to their users on
Android devices, without needing a proprietary sync
solution.

Wi-Fi Direct A technology that lets apps discover and pair directly, over
a high-bandwidth peer-to-peer connection.

Android Beam A popular NFC-based technology that lets users instantly


share, just by touching two NFC-enabled phones together.

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:

What is API level?


API Level is an integer value that uniquely identifies the framework API revision
offered by a version of the Android platform.

Platform API VERSION_CODE


Version Level

Android 5.1 22 LOLLIPOP_MR1

Android 5.0 21 LOLLIPOP

Android 4.4W 20 KITKAT_WATCH KitKat for


Wearables Only

Android 4.4 19 KITKAT

Android 4.3 18 JELLY_BEAN_MR2


Android 4.2, 17 JELLY_BEAN_MR1
4.2.2

Android 4.1, 16 JELLY_BEAN


4.1.1

Android 4.0.3, 15 ICE_CREAM_SANDWICH_MR1


4.0.4

Android 4.0, 14 ICE_CREAM_SANDWICH


4.0.1, 4.0.2

Android 3.2 13 HONEYCOMB_MR2

Android 3.1.x 12 HONEYCOMB_MR1

Android 3.0.x 11 HONEYCOMB

Android 2.3.4 10 GINGERBREAD_MR1


Android 2.3.3

Android 2.3.2 9 GINGERBREAD


Android 2.3.1
Android 2.3

Android 2.2.x 8 FROYO

Android 2.1.x 7 ECLAIR_MR1

Android 2.0.1 6 ECLAIR_0_1

Android 2.0 5 ÉCLAIR

Android 1.6 4 DONUT

Android 1.5 3 CUPCAKE


Android 1.1 2 BASE_1_1

Android 1.0 1 BASE

Installation of android:

To install Android Studio on Windows, follow these steps:

• If you downloaded an .exe file (recommended), double-click to launch it.


• If you downloaded a .zip file:
1. Unpack the .zip.
2. Copy the android-studio folder into your Program Files folder.
3. Open the android-studio > bin folder.
4. Launch studio64.exe (for 64-bit machines) or studio.exe (for 32-bit
machines).
5. Follow the Setup Wizard in Android Studio and install any recommended
SDK packages.
PRACTICAL NO. 2

AIM: Using the Development environment


a. Create a new Project using wizard
b. Add source and resource files.
c. Import existing projects into workspace
d. Create testing Emulator
e. Compile and run the project.
f. Debug android project

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.

Step 1: Create a New Project

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.

Figure 1. The Configure your new project screen.

Enter the values for your project then click Next.

Step 2: Select Form Factors and API Level


The next window lets you select the form factors supported by your app, such as
phone, tablet, TV, Wear, and Google Glass. The selected form factors become the
app modules within the project. For each form factor, you can also select the API
Level for that app. To get more information, click Help me choose.
Figure 2. Chart of the current Android version distributions, shown when you
click Help me choose.

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.

Step 3: Add an Activity

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.

Figure 4. The Add an Activity screen for a mobile form factor.

Choose an activity type then click Next.

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.

Figure 5. The Customize the Activity screen.

Enter the activity name, the layout name, and the activity title. Then click Finish.

Step 5: Develop Your App

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.

Running an App in the Android Emulator

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.

To start the emulator and run an app in your project:

1. Open an Android Studio project and select Run .

The Select Deployment Target dialog appears.


2. If you receive an error or warning message at the top of the dialog, click the link
to correct the problem or get more information.

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.

Notice for Windows 10 Anniversary Update users: The Android Emulator


currently does not support this update to Windows 10 (version 1607), due to a
new digital signing requirement for drivers such as the Intel HAXM driver, which
the Android Emulator requires.

Some errors you must fix before you can continue, such as certain Hardware
Accelerated Execution Manager (Intel® HAXM) errors.

3. In the Select Deployment Target dialog, select an existing emulator definition,


and then click OK.
If you don’t see a definition you want to use, click Create New Emulator to
launch the AVD Manager. After you define a new AVD, in the Select Deployment
Target dialog, click OK.
If you want to use this emulator definition as the default for your project,
select Use same selection for future launches.
The emulator launches and displays your app.
4. Test your app in the emulator.

5. To close the emulator, click Close .

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.

Launching the Android Emulator without Running an App

To start the emulator:

1. Open the AVD Manager.

2. Double-click an AVD, or click Run .

The Android Emulator appears.

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.

Debug Your App


• Create and Edit Run/Debug Configurations
Android Studio includes a debugger that allows you to debug apps running on the
Android Emulator or a connected Android device. With the Android Studio
debugger, you can:
• Select a device to debug your app on.
• Set breakpoints in your code.
• Examine variables and evaluate expressions at runtime.
• Capture screenshots and videos of your app.
To start debugging, click Debug in the toolbar. Android Studio builds an APK,
signs it with a debug key, installs it on your selected device, then runs it and opens
the Debug window.
If no devices appear in the Select Deployment Target window after you
click Debug, then you need to eitherconnect a device or click Create New
Emulator to setup the Android Emulator.
PROJECT NO. 3

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.

How to change API SDK level in Android Studio


For changing the API level in android we have two different Approaches, let’s
check both one by one:
Approach 1 To Change SDK API Level in Android Studio:
Step 1: Open your Android Studio, and go to Menu. File >Project Structure.
Step 2: In project Structure window, select app module in the list given on left
side.
Step 3: Select the Flavors tab and under this you will have an option for setting
“Min Sdk Version” and for setting “Target Sdk Version”.

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.

Approach 2 To Change API (Android Version) in Android Studio:


That will be pretty straight forward, but you need to stay very alert while making changes
here.
Step 1: if you are project is opened in android option then select open Gradle
Scripts > build.gradle(Module: app)
if you are in project View then click on your project folder > app > build.gradle
Step 2: Here you have to change minimum and Maximum sdk level as per your
requirement. check the below given code:
defaultConfig {

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;

public class MainActivity extends AppCompatActivity {


Button b1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=(Button)findViewById(R.id.but);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this,"WELCOME TO CHOUKSEY
ENGINEERING COLLEGE",Toast.LENGTH_LONG).show();
}
});
}
}

----------------------------------------------------------------------------
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;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

public void onButtonClick(View v) {


EditText e1 = (EditText) findViewById(R.id.editText);
EditText e2 = (EditText) findViewById(R.id.editText2);
TextView t1 = (TextView) findViewById(R.id.textView);
int num1 = Integer.parseInt(e1.getText().toString());
int num2 = Integer.parseInt(e2.getText().toString());
int sum = num1 + num2;

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;

public class MainActivity extends AppCompatActivity {


private static RadioGroup radio_g;
private static RadioButton radio_b;
private static Button button_sbm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
onClickListenerButton();
}
public void onClickListenerButton(){
radio_g=(RadioGroup) findViewById(R.id.rg_colleges);
button_sbm=(Button)findViewById(R.id.button);
button_sbm.setOnClickListener(
new View.OnClickListener(){
@Override
public void onClick(View view) {
int selected_id= radio_g.getCheckedRadioButtonId();
radio_b=(RadioButton)findViewById(selected_id);

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);

//Applying the Listener on the Button click


buttonOrder.setOnClickListener(new OnClickListener(){

@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;

public class MainActivity extends AppCompatActivity {


private static Button button_sbm;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
OnButtonClicklistener();
}

public void OnButtonClicklistener() {


button_sbm = (Button) findViewById(R.id.button);
button_sbm.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder a_builder = new
AlertDialog.Builder(MainActivity.this);
a_builder.setMessage("Do you want to close this
APP!!!").setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialogInterface, int i) {
finish();
}
}).setNegativeButton("No", new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.cancel();
}
});
AlertDialog alert = a_builder.create();
alert.setTitle("Alert !!!");
alert.show();
}
}

);

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;

public class MainActivity extends AppCompatActivity {


EditText edittext1;
Button button1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

//Getting the edittext and button instance


edittext1=(EditText)findViewById(R.id.editText1);
button1=(Button)findViewById(R.id.button1);

//Performing action on button click


button1.setOnClickListener(new OnClickListener(){

@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;

public class MainActivity extends Activity {

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);

//Performing action on button click


sendsms.setOnClickListener(new OnClickListener() {

@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);

//Get the SmsManager instance and call the sendTextMessage method to se


nd message
SmsManager sms=SmsManager.getDefault();
sms.sendTextMessage(no, null, msg, pi,null);

Toast.makeText(getApplicationContext(), "Message Sent successfully!",


Toast.LENGTH_LONG).show();
}
});
}

@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;

public class MainActivity extends AppCompatActivity {

private static Button button_sbm;


private static EditText url_text;
private static WebView browser;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void OpenUrl(){
button_sbm=(Button)findViewById(R.id.button);
url_text=(EditText)findViewById(R.id.editText);
browser=(WebView)findViewById(R.id.webView);
button_sbm.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
String url = url_text.getText().toString();
browser.getSettings().setLoadsImagesAutomatically(true);
browser.getSettings().setJavaScriptEnabled(true);
browser.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
browser.loadUrl(url);
}
}
);
}
}

12. Create Android camera app example by camera intent.


package com.example.dell.camera;

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;

public class MainActivity extends AppCompatActivity {


private static final int CAMERA_REQUEST = 1888;
ImageView imageView;
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

imageView = (ImageView) this.findViewById(R.id.imageView1);


Button photoButton = (Button) this.findViewById(R.id.button1);

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);
}
});
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {


if (requestCode == CAMERA_REQUEST) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
}

}
OUTPUT:

********

You might also like