0% found this document useful (0 votes)
74 views68 pages

Updated MAD Lab File

NetBeans is a free, open-source integrated development environment written in Java. It provides tools for developing desktop, enterprise, web, and mobile applications using languages like Java, C/C++, PHP, JavaScript, Groovy, and Ruby. Minimum system requirements include 512MB RAM, 750MB disk space, and a dual-core processor. To install, download the NetBeans installer, accept the license agreement, and select an installation directory. The JDK must also be installed to develop Java applications in NetBeans.

Uploaded by

Paritosh Belekar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views68 pages

Updated MAD Lab File

NetBeans is a free, open-source integrated development environment written in Java. It provides tools for developing desktop, enterprise, web, and mobile applications using languages like Java, C/C++, PHP, JavaScript, Groovy, and Ruby. Minimum system requirements include 512MB RAM, 750MB disk space, and a dual-core processor. To install, download the NetBeans installer, accept the license agreement, and select an installation directory. The JDK must also be installed to develop Java applications in NetBeans.

Uploaded by

Paritosh Belekar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 68

Shri Vaishnav Vidyapeeth Vishwavidyalaya, Indore

Shri Vaishnav Institute of Information Technology


Department of Information & Technology

LAB FILE

Subject: Mobile App Development Lab


Enrollment Number: 20100BTCSICS07343
Course Code: BTIT - 306
II-Year/IV-Semester - Section (G)

Submitted By:-                                                                  Subject Teacher:-


Paritosh Belekar                     Mrs. Isha Chopra

1
INDEX

S.NO EXPERIMENTS PAGE NO.

1 File Handling in C, C++ and JAVA 3

2 Packages in JAVA 11

3 Case Study on NetBeans 12

4 Installation of Eclipse 19

5 Case study on Kotlin

6 Study Different Open-Source Mobile Development Tools

7 Introduction of Android

8 Case study on Android Studio

9 Steps to install Android Studio

Develop an Android Application that uses GUI components,


10
Font and Colors

Develop an Android Application for Layout Managers & Event


11
Listeners

12 Develop an Android application for native Calculator

Develop an Android application that draws basic Graphical


13
Primitives on the Screen

14 Develop an Android application that makes use of Database

15 Develop a Android application that creates Alarm Clock

2
Practical 1 : File Handling in C, C++ & JAVA.
a)File Handling in c.
#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

#define N 50

struct Student

{ char name[20];

char rollno[20];

char fathername[20];

char mothername[20];

long long cont;

};

main()

{ struct Student s[N];

int v,i;

printf("Enter the number of students: ");

scanf("%d",&v);

FILE *p;

p=fopen("Student.txt","w");

for(i=0;i<v;i++)

{ printf("Enter name: ");

scanf(" %s",&s[i].name);

printf("Enter rollnumber: ");

scanf("%s",&s[i].rollno);

3
printf("Enter father's name: ");

scanf(" %s",&s[i].fathername);

printf("Enter mother's name: ");

scanf(" %s",&s[i].mothername);

printf("Enter contact number: ");

scanf("%lld",&s[i].cont);

printf("\n");

fprintf(p,"Name:%s\n",s[i].name);

fprintf(p,"Rollnumber:%s\n",s[i].rollno);

fprintf(p,"father's name':%s\n",s[i].fathername);

fprintf(p,"mother's name':%s\n",s[i].mothername);

fprintf(p,"Contact Number:%lld\n",s[i].cont);

fclose(p);

printf("Details from File: \n");

FILE *p1;

p1=fopen("Student.txt","r");

char c;

while(1)

if(p1==NULL)

printf("file not found");

else

c=fgetc(p1);

4
if(c==EOF)

break;

printf("%c",c);

fclose(p1);

OUTPUT:

b)File handling in c++.


#include<iostream>

5
#include<fstream>

#define N 50

using namespace std;

class Student

{ public:

char name[20];

char rollno[20];

char course[20];

char sec;

};

main()

Student s[N];

int a,i;

cout<<"Enter the number of students : ";

cin>>a;

ofstream fout;

fout.open("Student1.txt");

for(i=0;i<a;i++)

cout<<"Enter name : ";

cin>>s[i].name;

cout<<"Enter Roll Number : ";

cin>>s[i].rollno;

cout<<"Enter course : ";

6
cin>>s[i].course;

cout<<"Enter Class Section : ";

cin>>s[i].sec;

cout<<"\n";

fout<<"Name :"<<s[i].name<<endl;

fout<<"Roll Number :"<<s[i].rollno<<endl;

fout<<"Course :"<<s[i].course<<endl;

fout<<"Class Section :"<<s[i].sec<<endl;

fout.close();

printf("Showing Your Details from File : \n");

ifstream fin;

fin.open("Student1.txt");

string tp;

while(getline(fin,tp))

{ cout<<tp<<endl; }

fin.close();

OUTPUT:

7
8
c)File handling in java.
FILE WRITER
import java.util.*;
import java.io.*;
class Info
{
   String name;
   int roll;
}
public class A
{
public static void main(String[] args) throws IOException
{
Scanner sc = new Scanner(System.in);
Info obj = new Info();
FileWriter fw= new FileWriter("file.txt");
        obj.name=sc.nextLine();
        fw.write(obj.name);
           fw.close();
}
}

FILE READER
import java.io.*;
import java.util.*;
public class B
{
public static void main(String[] args) throws IOException
{

9
FileReader fr=null;
try
{
                 fr=new FileReader("file.txt");
    }catch(Exception e)
  {
   System.out.println("File Not Found");
  }
int a;
while((a=fr.read())!=-1)
{
System.out.print((char)a);
}
fr.close();
}
}

OUTPUT:

10
11
1) java.lang: Contains language support classes(e.g classed which defines primitive data
types, math operations). This package is automatically imported
2) java.io: Contains classed for supporting input / output operations.
3) java.util: Contains utility classes which implement data structures like Linked List,
Dictionary and support ; for Date / Time operations.
4) java.applet: Contains classes for creating Applets
5) java.awt: Contain classes for implementing the components for graphical user interfaces
(like button, menus etc).
6) java.net: Contain classes for supporting networking operations.
7) java.math: multiprecision arithmetics
8) java.nio: the Non-blocking I/O framework for Java
9) java.security: key generation, encryption and decryption
10) java.sql: Java Database Connectivity (JDBC) to access databases
11) javax.swing: hierarchy of packages for platform-independent rich GUI components
12) java.beans: Contains classes related to developing beans -- components based on the
JavaBean architecture.
13) java.text: Provides classes and interfaces for handling text, dates, numbers, and
messages in a manner independent of natural languages.
14) java.rmi: Java API for remote method invocations.
15) java.time: The main API for dates, times, instants, and durations.
16) java.awt.color: provides classes for color spaces.
17) java.awt.fonts: provides classes and interface relating to fonts.
18) java.awt.image: provides classes for creating and modifiying images.
19) java.awt.datatransfer: provides interfaces and classes for transferring data between and
within applications.
20) javax.imageio: The main package of the java image I/O API.

12
Practical 3 :Case Study of NetBeans

NetBeans: The NetBeans IDE is a free, open-source integrated development environment


written entirely in Java. It offers a range of tools for create professional desktop, enterprise, web,
and mobile applications with the Java language, C/C++, and even scripting languages such as
PHP, JavaScript, Groovy, and Ruby.

Minimum System Requirement:


Microsoft Windows Vista SP1/Windows 7 Professional:
 Processor: 800MHz Intel Pentium III or equivalent
 Memory: 512 MB
 Disk space: 750 MB of free disk space

Ubuntu 9.10:
 Processor: 800MHz Intel Pentium III or equivalent
 Memory: 512 MB
 Disk space: 650 MB of free disk space

Macintosh OS X 10.7 Intel:


 Processor: Dual-Core Intel
 Memory: 2 GB
 Disk space: 650 MB of free disk space

Installation of NetBeans
Install JDK: To use NetBeans for Java programming, you need to first install Java Development
Kit (JDK). See “JDK - How to Install”.

1. After the download completes, run the installer.


 For Windows, the installer executable file has the .exe extension. Double-click the
installer file to run it.
 For Linux platforms, the installer file has the .sh extension. For these platforms,
you need to make the installer files executable by using the following
command: chmod +x <installer-file-name>. Type ./<installer-file-name> to run
the installer.
If you downloaded the All or Java EE bundle, you can customize your installation. Perform
the following steps at the Welcome page of the installation wizard:
1. Click Customize.
2. In the Customize Installation dialog box, make your selections.
3. Click OK.

13
At the Welcome page of the installation wizard, click Next.
At the License agreement page, review the license agreement, click the acceptance check
box, and click Next.
At the NetBeans IDE installation page, do the following:
1. Accept the default installation directory for the NetBeans IDE or specify another
directory.
Note: The installation directory must be empty and the user profile you are using to run
the installer must have read/write permissions for this directory.
2. (Applicable only to All or Java EE bundle.) Accept the default JDK installation
to use with the NetBeans IDE or select a different installation from the drop-down
list. If the installation wizard did not find a compatible JDK installation to use
with the NetBeans IDE, your JDK is not installed in the default location. In this
case, specify the path to an installed JDK and click Next, or cancel the current
installation. After installing the required JDK version you can restart the
installation.
Note: If the JDK version is older than the recommended JDK 8, download and install the
latest JDK update from Java SE Downloads page and restart the NetBeans IDE installer.
Click Next.
If the GlassFish Server Open Source Edition 4.1.1 installation page opens, accept the default
installation directory or specify another installation location and click Next.
If you are installing Apache Tomcat, on its installation page, accept the default installation
directory or specify another installation location. Click Next.
At the Summary page, do the following:
1. Verify that the list of components to be installed is correct.
2. Select the Check for Updates check box if you want to check the Update Center
for possible updates.
3. Verify that you have adequate space on your system for the installation.
Click Install to begin the installation.
At the Setup Complete page, provide anonymous usage data if desired, and click Finish.

Use of NetBeans:
Through the NetBeans IDE build process, which relies on industry standards such as Apache
Ant, make, Maven, and rake - rather than a proprietary build process -you can easily customize
projects and add functionality. You can build, run, and deploy projects to servers outside of the
IDE.

Features of NetBeans:

 Fast & Smart Code Editing


An IDE is much more than a text editor. The NetBeans Editor indents lines, matches words and

14
brackets, and highlights source code syntactically and semantically. It lets you easily refactor
code, with a range of handy and powerful tools, while it also provides code templates, coding
tips, and code generators.

 Easy & Efficient Project Management


Keeping a clear overview of large applications, with thousands of folders and files, and millions
of lines of code, is a daunting task. NetBeans IDE provides different views of your data, from
multiple project windows to helpful tools for setting up your applications and managing them
efficiently, letting you drill down into your data quickly and easily, while giving you versioning
tools via Subversion, Mercurial, and Git integration out of the box.

 Rapid User Interface Development


Design GUIs for Java SE, HTML5, Java EE, PHP, C/C++, and Java ME applications quickly
and smoothly by using editors and drag-and-drop tools in the IDE. For Java SE applications, the
NetBeans GUI Builder automatically takes care of correct spacing and alignment, while
supporting in-place editing, as well. The GUI builder is so easy to use and intuitive that it has
been used to prototype GUIs live at customer presentations.

 Write Bug Free Code


The cost of buggy code increases the longer it remains unfixed. NetBeans provides static
analysis tools, especially integration with the widely used FindBugs tool, for identifying and
fixing common problems in Java code. In addition, the NetBeans Debugger lets you place
breakpoints in your source code, add field watches, step through your code, run into methods,
take snapshots and monitor execution as it occurs.

 Support for Multiple Languages


NetBeans IDE offers superior support for C/C++ and PHP developers, providing comprehensive
editors and tools for their related frameworks and technologies. In addition, the IDE has editors
and tools for XML, HTML, PHP, Groovy, Javadoc, JavaScript, and JSP.

 Project Views
The Projects window is the main entry point to your project sources. It shows a logical view of
important project Content. In addition to the Projects window, the IDE provides the Files
window, so that you can see all the files that belong to a project, and the Favorites window,
where you can add folders and files so that they can be browsed within the IDE.

15
Basic Project Concepts

 Projects
In the IDE, you always work inside of a project. In addition to source files, an IDE project
contains metadata about what belongs on the classpath, how to build and run the project, and so
on. The IDE stores project information in a project folder which includes an Ant build script and
properties file that control the build and run settings, and a project.xml file that maps Ant targets
to IDE commands.

 Creating a Project
To create a new project:
Choose File New Project (Ctrl-Shift-N on Windows/Cmd-Shift-N on OS X). When the New
Project wizard appears, select the right template for your project and complete the remaining
wizard steps. The project template icon can be displayed in gray, which means that this project
type has not been activated. Proceed with creating the project and this functionality will be
activated in the IDE.

The IDE contains the following standard project templates for Java and Java Web applications:

1. Java Application. Creates a skeleton Java SE project with a main class.


2. Java Class Library. Creates a skeleton Java class library without a main class. Java
Project with Existing Sources. Creates a Java SE
3. Project based on your own Java sources
4. Web Application. Creates a skeleton web application, including options to add various
web frameworks.
5. Web Application with Existing Sources. Creates a web project based on your own web
and Java sources.
In addition, the IDE also contains templates for EJB modules, enterprise applications, Java ME
applications, and more.

The Java and Web project categories also have free-form project templates. The free-form
templates enable you to use an existing Ant script for a project but require manual configuration
When you finish creating a project, it opens in the IDE with its logical structure displayed in the
Projects window and its file structure displayed in the Files window:

6. The Projects window is the main entry point to your project sources. It shows a logical
view of important project
7. contents such as Java packages and Web pages. You can right-click any project node to
access a popup menu of commands for building, running, and debugging the project, as
well as opening the Project Properties dialog box.

16
8. The Projects window can be opened by choosing Window &gt; Projects (Ctrl-1 on
Windows/Cmd-1 on OS X).
9. The Files window shows a directory-based view of your projects, including files and
folders that are not displayed
10. in the Projects window. From the Files window, you can open and edit your project
configuration files, such as the
11. project & build script and properties file. You can also view build output like compiled
classes, JAR files, WAR files, and generated Javadoc documentation. The Files window
can be opened by choosing Window & Files (Ctrl-2 on Windows/Cmd -2 on OS X).

NetBeans Libraries:
NetBeans projects are already generally portable between different users, whether or not they use
the IDE. However, by default, the project build script way of referring to libraries is dependent
on factors specific to each user, particularly in the case of libraries defined in the Library
Manager dialog box.

Supported Technologies, Servers, and Mobile Platforms NetBeans IDE 8.2 supports the
following technologies and has been tested with the following application servers and mobile
platforms. If you plan to use versions other than those explicitly listed, please note that you may
encounter unpredictable IDE behavior.

Supported technologies:
 Java EE 7, Java EE 6, and Java EE 5
 JavaFX 2.2.x and 8
 Java ME SDK 8.0
 Java Card 3 SDK
 Struts 1.3.10
 Spring 4.0.1, 3.2.7, 2.5
 Hibernate 4.2.6, 3.6.10
 Issue Tracking
 Bugzilla 4.4 and earlier
 Jira 3.13+ and 5.0+
 Node.js 4.0+
 PHP 7, 5.6, 5.5, 5.4, 5.3, 5.2, 5.1
 Groovy 2.1
 Grails 2.3, 2.2
 Apache Ant 1.9.7
 Apache Maven 3.0.5 and earlier
 C/C++/Fortran

17
VCS
 Subversion: 1.8, 1.7, 1.6
 Mercurial: 2.8.x and later
 Git 1.8.х and later

Tested application servers:


 GlassFish Server Open Source Edition 4.1.1
 WebLogic 12c

Known to run application servers:


 GlassFish Server Open Source Edition 3.x
 Tomcat 7.x and 8.0.27
 WildFly 8, 9, and 10
 JBoss AS 7.x
 WebLogic 11g

Tested mobile platforms:


 Android 4.4
 iOS 7.0
 Cordova 3.3

Known to run mobile platforms:


 iOS 7.1
 Cordova 3.4

SQL Editor and Databases


The following changes have been made to the database functionality in NetBeans IDE 8.2:
 Upgraded Drivers. The MySQL drivers included in NetBeans IDE have been updated to
version 6.0.

Tested Drivers: NetBeans IDE 8.2 has been tested with the following databases and drivers.
 

18
Open Source Tools For Java
 Eclipse:
Eclipse is an integrated development environment (IDE) which is used for almost every language
using Plugins. Currently, it consists of more than 150 projects covering different aspects of
software development.
Tool Features:
 It is an Open source development environment that runs in the cloud.
 Apart from Java, it supports other languages using plug-ins like C, C++, Perl, Python,
and JavaScript.
 It has SDK for Java development tools, which in turn helps the Java developers and
supports development for Tomcat, GlassFish, and many other servers.
 This tool is more popular and is widely used everywhere in organizations. It makes code
simple, easy to understand and debug.

 NetBeans:
NetBeans is another IDE which is used for developing java codes. It runs on almost every
platform like Windows, Linux, Solaris, and MacOS. Like Eclipse it is also an open source
environment and can be used to develop other programming languages like C, C++, JavaScript
etc.
Features:
 It is a framework that is used for the development of Java Swing desktop application.
 Used for saving and loading any type of data.
 Supports step by step dialogues for Wizard Framework.
 Open source Integrated development tools.
 
 
Open Source Tools For Database
 PostgreSQL:
PostgreSQL is an open source database that comes with features such as data indexing, user
configuration settings, data import/export, and version control. While PostgreSQL is a relational
database, it also allows creating NoSQL databases with programming languages such as Python
and JSON. Users mention that the tool has a large open source community that has built several
plugins for the tool, improving its functionality.

 DBeaver:
DBeaver is an SQL client and a database administration tool. For relational databases it uses the
JDBC API to interact with databases via a JDBC driver. For other databases it uses proprietary
database drivers. It provides an editor that supports code completion and syntax highlighting.
The community edition (CE) of DBeaver is \a free and open source software that is distributed
under the Apache License.

19
Practical 4: Installation of Eclipse
1. Download the Eclipse Installer
Download Eclipse Installer from http://www.eclipse.org/downloads. Eclipse is hosted on many
mirrors around the world. Please select the one closest to you and start to download the Installer
2. Start the Eclipse Installer executable
For Windows users, after the Eclipse Installer executable has finished downloading it should be
available in your download directory. Start the Eclipse Installer executable. You may get a
security warning to run this file. If the Eclipse Foundation is the Publisher, you are good to select
Run.
For Mac and Linux users, you will still need to unzip the download to create the Installer. Start
the Installer once it is available.
3. Select the package to install
The new Eclipse Installer shows the packages available to Eclipse users. You can search for the
package you want to install or scroll through the list. Select and click on the package you want to
install.
4. Select your installation folder
Specify the folder where you want Eclipse to be installed. The default folder will be in your User
directory. Select the ‘Install’ button to begin the installation.
5. Launch Eclipse
Once the installation is complete you can now launch Eclipse. The Eclipse Installer has done it's
work. Happy coding.

20
Practical 5: Case Study on Kotlin

21
Practical 6 : Study Different Open Source Mobile Development
Tools.

1. PhoneGap:-
PhoneGap is a popular open-source mobile app development software that allows you to create
hybrid applications. With PhoneGap, the developer doesn’t necessarily need to know mobile
programming languages. Instead, they can get started with languages like CSS, HTML, and
JavaScript for app creation.
In fact, it allows you to create apps that will work for multiple platforms with a single codebase
to reach the maximum number of audience. 

Features
 Easily integrates with various libraries for developing the app, 
 Allows you to view and manage any changes in the app using PhoneGap
 Operates on multiple operating systems, including iPhone, Android, and Windows 

2. Flutter:
Flutter is a free mobile app development software that is best suited for hybrid apps. It is one of
the newest members in the mobile app development space and is written in C, C++, and Skia
Graphics Engine. 
It is Google’s UI toolkit that enables you to create applications for mobile, web, and desktop
from a single codebase. What’s more, you don’t have to restart the application when testing your
project. It offers the Hot Reload functionality, which makes the whole process of development
stress-free and optimized. 

Features
 Incorporate all critical platform differences such as navigation, scrolling, icons, and fonts
 Offers fully-customizable widgets to render fast development of native apps 
 Creates plugins using channels to be easily used by every developer

3. Ionic:
Ionic is another best free, open source mobile app development software mostly preferred for
creating hybrid apps. The best thing is that it allows you to build applications for various
platforms, including Android, iOS, and web — using a single codebase. 
What’s more, it offers intuitive UI components that accelerate the app development process.
Besides, it can be deployed virtually anywhere. Ionic boasts over 120 native device features,
predefined elements, and a large community of developers.

Features
 Includes interactive paradigms, mobile components, typography, and an extensible base
theme
 Written in JavaScript, the program is covered by the MIT license
 Allows for Cordova based app building

22
 Popular technologies and ease of learning

4. Xamarin:
Xamarin is a free and open-source mobile app development application founded by Microsoft in
2011. It is a set of tools that enables developers to build apps for various operating systems,
including Windows, Android, and iOS — all in one programming language. 
One of the reasons why Xamarin is quite popular is that it uses the C# programming language.
Besides, using the Xamarin Test Cloud, you can automatically test apps on around 2,000 real
mobile devices. 

Features
 Offers a real-time testing module to monitor and catch app errors as and when they
happen
 Easily integrates with modern backend services, components, native APIs, and more
 Enables you to build stunning cross-platform user interfaces

5. BuildFire:
Another best in the category of free mobile app development software is Buildfire. It offers a
robust set of tools to build apps for both Android and iOS. It is well-known for its high-end
custom development capabilities as well as an easy, intuitive DIY platform. 
What’s more, it currently supports more than 10,000 apps and is flexible enough to scale as your
business starts to grow. You can’t ignore the simple and functional drag-and-drop UI either, as it
makes it easy to build the app quickly.
 
Features
 Allows you to build custom functionality with their developer SDK
 Offer an interactive intuitive app builder where no coding is required
 Can be combined with any third-party API’s or pre-built integrations

6. Flego:
Felgo is a free mobile app development software that supports apps for various platforms,
including iOS, Android, desktop (Windows and Linux), and counting. Using a single codebase,
you can create an application for different operating systems. 
Well, it was ranked first as the most time-saving framework, easiest to learn, and best support
system as compared to other 40 leading tools. Besides, it’s a great system to develop game apps
as it supports 3D objects too. 

Features
 Uses custom UI rendering to reduce the interaction between the native layer and runtime
environment
 Provides a well-designed abstraction of platform-specific concepts
 Supports creating both business apps and gaming apps 

23
Practical 8: Case Study on Android Studio

Android Studio:
Android Studio is the official integrated development environment (IDE) for Android application
development. It is based on the IntelliJ IDEA, a Java integrated development environment for
software, and incorporates its code editing and developer tools.
Android Studio was announced on May 16, 2013 at the Google I/O conference. It was in early
access preview stage starting from version 0.1 in May 2013, then entered beta stage starting from
version 0.8 which was released in June 2014

Minimum System Requirement:


Windows

 4 GB RAM minimum, 8 GB RAM recommended


 2 GB of available disk space minimum, 4 GB Recommended (500 MB for IDE + 1.5 GB
for Android SDK and emulator system image)
 1280 x 800 minimum screen resolution
 Microsoft Windows 7/8/10 (32- or 64-bit). The Android Emulator supports 64-bit
Windows only

MAC

 4 GB RAM minimum, 8 GB RAM recommended


 2 GB of available disk space minimum, 4 GB Recommended (500 MB for IDE + 1.5 GB
for Android SDK and emulator system image)
 1280 x 800 minimum screen resolution
 Mac OS X 10.10 or higher

Linux

 4 GB RAM minimum, 8 GB RAM recommended


 2 GB of available disk space minimum, 4 GB Recommended (500 MB for IDE + 1.5 GB
for Android SDK and emulator system image)
 1280 x 800 minimum screen resolution
 GNOME or KDE desktop
 GNU C Library (glibc) 2.19 or later
 64-bit distribution capable of running 32-bit applications

Installation of Android Studio

1. So let's launch Android Studio.exe, Make sure before launch Android Studio, Our
Machine should required installed Java JDK.
2. Once you launched Android Studio, its time to mention JDK7 path or later
version in android studio installer.

24
3. Then you need to check the components, which are required to create
applications, you have to select from options like Android Studio, Android
SDK, Android Virtual Machine and performance (Intel chip) etc.
4. Then you need to specify the location of local machine path for Android studio
and Android SDK.
5. Then need to specify the ram space for Android emulator by default it would take
512MB of local machine RAM.
6. At final stage, it would extract SDK packages into our local machine, it would
take a while time to finish the task and would take 2626MB of Hard disk space.
7. After done all above steps perfectly, you must get finish button and it gonna be
open android studio project with Welcome to android studio message
8. You can start your application development by calling start a new android studio
project. in a new installation frame should ask Application name, package
information and location of the project

Features of Android Studio


1. Instant App Run: It is an advanced technology in which it cleverly understands
the transmutations done in the applications and deliver it instantly without taking
time to rebuild the apk and installations make.
2. Visual Layout Editor: Layout editor helps to build the layout quickly by adding
different attributes either by hard-code or drag and drop. The preview of the codes
can be seen easily on the visual editor screen and changes can be made
accordingly by resizing it dynamically.
3. Fast Emulator:  Android has a great feature of Emulator which is exactly like the
android phones to test how the application looks like in physical devices. It gives
real-time experience to the Android applications
4. Intelligence Code Editor: Android Studio provides you with the intelligent and
quick code editor. This will help you and guide you with the accurate code. It
helps you to complete code in advance and analyse your code in advance before
building.
5. Adding of  New Activity as a Code Template: Yes, Android also has the feature
of templates built-in. If you know to build that accordingly that makes your task
easier.
6. Help to Build Up App for All Devices: Android studio builds applications for
every screen size, for wear and gear devices etc. It also can stimulate the various
type of features which a hardware has like GPS location tracker, multi-touch.
7. Colour Previews: Android studio helps to see the code XML part in a preview to
know that how perfectly we are designing the application according to the need
before launching the application.
8. Maven Repository: In Android Studio, Maven integration of its repository can be
done, within SDK manager support libraries of IDE is used. It’s a kind of a
repository which is a directory in which various jar files like project jars, Plugin
are stored.

25
Language Supported by Android Studio

Android Studio supports all the same programming languages of IntelliJ (and CLion) e.g. Java, C++,
and more with extensions, such as Go; and Android Studio 3.0 or later supports Kotlin and "all Java
7 language features and a subset of Java 8 language features that vary by platform version. External
projects backport some Java 9 features. While IntelliJ that Android Studio is built on supports all
released Java versions, and Java 12, it's not clear to what level Android Studio supports Java
versions up to Java 12 (the documentation mentions partial Java 8 support)

Use of Android Studio

It is purpose built for Android to accelerate your development and help you build the highest-quality
apps for every Android device. It is best platform where you can design and code your android app.

Project Structure
Each project in Android Studio contains one or more modules with source code files and resource
files. Types of modules include:
 Android app modules
 Library modules
 Google App Engine modules

Android Studio User Interface


The toolbar lets you carry out a wide range of actions, including running your app and launching
Android tools.
1. The navigation bar helps you navigate through your project and open files for editing.
It provides a more compact view of the structure visible in the Project window.
2. The editor window is where you create and modify code. Depending on the current file
type, the editor can change. For example, when viewing a layout file, the editor displays
the Layout Editor.
3. The tool window bar runs around the outside of the IDE window and contains the
buttons that allow you to expand or collapse individual tool windows.
4. The tool windows give you access to specific tasks like project management, search,
version control, and more. You can expand them and collapse them.
5. The status bar displays the status of your project and the IDE itself, as well as any
warnings or messages.

26
Practical 9 : Steps to install Android Studio

27
Practical 10 : Develop an Application that uses GUI Components,
Font and Colors.

Code for Activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:gravity="center"
android:text="Hello World!"
android:textSize="25sp"
android:textStyle="bold" />

<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:gravity="center"
android:text="Change font size"
android:textSize="25sp" />

<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:gravity="center"
android:text="Change color"
android:textSize="25sp" />
</LinearLayout>

28
Code for MainActivity.java:

package com.example.exno1;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity
{
int ch=1; float font=30;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView t= (TextView) findViewById(R.id.textView);
Button b1= (Button) findViewById(R.id.button1);
b1.setOnClickListener(new View.OnClickListener() {
@Override

public void onClick(View v)


{
t.setTextSize(font);
font = font + 5;
if (font == 50)
font = 30;
}
});
Button b2= (Button) findViewById(R.id.button2);
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
switch (ch)
{
case 1:
t.setTextColor(Color.RED);
break;
case 2:
t.setTextColor(Color.GREEN);
break;
case 3:
t.setTextColor(Color.BLUE);
break;

29
case 4:
t.setTextColor(Color.CYAN);
break;
case 5:
t.setTextColor(Color.YELLOW);
break;
case 6:
t.setTextColor(Color.MAGENTA); break;
}
ch++;
if (ch == 7)
ch = 1;
}
});
}
}

OUTPUT:

30
Practical 11 : Develop an Android Application for Layout Managers
& Event Listeners
Code for 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"

    tools:context=".MainActivity">

    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="100dp">

        <TextView

            android:id="@+id/textView"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:layout_margin="30dp"

            android:text="Details Form"

            android:textSize="25sp"

            android:gravity="center"/>

    </LinearLayout>

     <GridLayout

        android:id="@+id/gridLayout"

        android:layout_width="match_parent"

31
        android:layout_height="match_parent"

        android:layout_marginTop="100dp"

        android:layout_marginBottom="200dp"

        android:columnCount="2"

        android:rowCount="3">

        <TextView

            android:id="@+id/textView1"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_margin="10dp"

            android:layout_row="0"

            android:layout_column="0"

            android:text="Name"

            android:textSize="20sp"

            android:gravity="center"/>

         <Edit Text

            andr oid:id="@+
id/editText"

            andr oid:layout_
width="wra p_content"

            andr oid:layout_
height="wra p_content"

            andr oid:layout_
margin="10 dp"

            andr oid:layout_r
ow="0"

32
            android:layout_column="1"

            android:ems="10"/>

        <TextView

            android:id="@+id/textView2"

  android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_margin="10dp"

            android:layout_row="1"

            android:layout_column="0"

            android:text="Reg.No"

            android:textSize="20sp"

            android:gravity="center"/>

<EditText

            android:id="@+id/editText2"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_margin="10dp"

            android:layout_row="1"

            android:layout_column="1"

            android:inputType="number"

            android:ems="10"/>

         <TextView

            android:id="@+id/textView3"

33
            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_margin="10dp"

            android:layout_row="2"

            android:layout_column="0"

            android:text="Dept"

            android:textSize="20sp"

            android:gravity="center"/>

         <Spinner

            android:id="@+id/spinner"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_margin="10dp"

            android:layout_row="2"

            android:layout_column="1"

            android:spinnerMode="dropdown"/>

    </GridLayout>

    <Button

        android:id="@+id/button"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignParentBottom="true"

        android:layout_centerInParent="true"

        android:layout_marginBottom="150dp"

34
        android:text="Submit"/>

</RelativeLayout>

35
Code for Activity_second.xml:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout 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"

    tools:context="com.example.devang.exno2.SecondActivity"

    android:orientation="vertical"

    android:gravity="center">

    <TextView

        android:id="@+id/textView1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_margin="20dp"

        android:text="New Text"

        android:textSize="30sp"/>

    <TextView

        android:id="@+id/textView2"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_margin="20dp"

        android:text="New Text"

        android:textSize="30sp"/>

36
 

    <TextView

        android:id="@+id/textView3"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_margin="20dp"

        android:text="New Text"

        android:textSize="30sp"/>

</LinearLayout>

37
Code for MainActivity.java:

package com.example.exno2;

import android.content.Intent;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.ArrayAdapter;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Spinner;

public class MainActivity extends AppCompatActivity {

    //Defining the Views

    EditText e1,e2;

    Button bt;

    Spinner s;

    //Data for populating in Spinner

    String [] dept_array={"CSE","ECE","IT","Mech","Civil"};

    String name, reg, dept;

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

         //Referring the Views

        e1= (EditText) findViewById(R.id.editText);

38
        e2= (EditText) findViewById(R.id.editText2);

         bt= (Button) findViewById(R.id.button);

         s= (Spinner) findViewById(R.id.spinner);

         //Creating Adapter for Spinner for adapting the data from array to Spinner

        ArrayAdapter adapter= new ArrayAdapter


(MainActivity.this,android.R.layout.simple_spinner_item,dept_array);

        s.setAdapter(adapter);

         //Creating Listener for Button

        bt.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View v) {

                 //Getting the Values from Views(EditText & Spinner)

                name=e1.getText().toString();

                reg=e2.getText().toString();

                dept=s.getSelectedItem().toString();

                 //Intent For Navigating to Second Activity

                Intent i = new Intent(MainActivity.this,SecondActivity.class);

                 //For Passing the Values to Second Activity

                i.putExtra("name_key", name);

                i.putExtra("reg_key",reg);

                i.putExtra("dept_key", dept);

                 startActivity(i);

             }

        });

    }}

39
Code for SecondActivity.java:

package com.example.exno2;

 import android.content.Intent;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.widget.TextView;

public class SecondActivity extends AppCompatActivity {

    TextView t1,t2,t3;

    String name,reg,dept;

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_second);

        t1= (TextView) findViewById(R.id.textView1);

        t2= (TextView) findViewById(R.id.textView2);

        t3= (TextView) findViewById(R.id.textView3);

         //Getting the Intent

        Intent i = getIntent();

        //Getting the Values from First Activity using the Intent received

        name=i.getStringExtra("name_key");

        reg=i.getStringExtra("reg_key");

        dept=i.getStringExtra("dept_key");

         //Setting the Values to Intent

        t1.setText(name);

        t2.setText(reg);

40
        t3.setText(dept);

     }

OUTPUT:

41
Practical 12 : Develop an Android application for native Calculator

Code for Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="20dp">
    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"> 
        <EditText
            android:id="@+id/editText1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:inputType="numberDecimal"
            android:textSize="20sp" />
        <EditText
            android:id="@+id/editText2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:inputType="numberDecimal"
            android:textSize="20sp" />
   </LinearLayout>
    <LinearLayout

42
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="20dp">
 
        <Button
            android:id="@+id/Add"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="+"
            android:textSize="30sp"/>
        <Button
            android:id="@+id/Sub"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="-"
            android:textSize="30sp"/>
        <Button
            android:id="@+id/Mul"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="*"
            android:textSize="30sp"/>
        <Button
            android:id="@+id/Div"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"

43
            android:text="/"
            android:textSize="30sp"/>
    </LinearLayout>
    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:text="Answer is"
        android:textSize="30sp"
        android:gravity="center"/>
</LinearLayout>

44
Code for MainActivity.java:

package com.example.devang.exno3;
 import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
 public class MainActivity extends AppCompatActivity implements OnClickListener
{
    //Defining the Views
    EditText Num1;
    EditText Num2;
    Button Add;
    Button Sub;
    Button Mul;
    Button Div;
    TextView Result;
     @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         //Referring the Views
        Num1 = (EditText) findViewById(R.id.editText1);
        Num2 = (EditText) findViewById(R.id.editText2);
        Add = (Button) findViewById(R.id.Add);
        Sub = (Button) findViewById(R.id.Sub);

45
        Mul = (Button) findViewById(R.id.Mul);
        Div = (Button) findViewById(R.id.Div);
        Result = (TextView) findViewById(R.id.textView);
         // set a listener
        Add.setOnClickListener(this);
        Sub.setOnClickListener(this);
        Mul.setOnClickListener(this);
        Div.setOnClickListener(this);
    }
      @Override
    public void onClick (View v)
    {
        float num1 = 0;
        float num2 = 0;
        float result = 0;
        String oper = "";
         // check if the fields are empty
        if (TextUtils.isEmpty(Num1.getText().toString()) || TextUtils.isEmpty(Num2.getText().toString()))
                return;
         // read EditText and fill variables with numbers
        num1 = Float.parseFloat(Num1.getText().toString());
        num2 = Float.parseFloat(Num2.getText().toString());
 
        // defines the button that has been clicked and performs the corresponding operation
        // write operation into oper, we will use it later for output
        switch (v.getId())
        {
            case R.id.Add:
                oper = "+";
                result = num1 + num2;
                break;

46
            case R.id.Sub:
                oper = "-";
                result = num1 - num2;
                break;
            case R.id.Mul:
                oper = "*";
                result = num1 * num2;
                break;
            case R.id.Div:
                oper = "/";
                result = num1 / num2;
                break;
            default:
                break;
        }
        // form the output line
        Result.setText(num1 + " " + oper + " " + num2 + " = " + result);
    }
}
OUTPUT:

47
Practical 13 : Develop an Android application that draws basic
Graphical Primitives on the Screen
Code for Activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent">

<ImageView

android:layout_width="match_parent"

android:layout_height="match_parent"

android:id="@+id/imageView" />

</RelativeLayout>

48
Code for MainActivity.java:

package com.example.exno4;

import android.app.Activity;

import android.graphics.Bitmap;

import android.graphics.Canvas;

import android.graphics.Color;

import android.graphics.Paint;

import android.graphics.drawable.BitmapDrawable;

import android.os.Bundle;

import android.widget.ImageView;

public class MainActivity extends Activity

@Override

public void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

//Creating a Bitmap

Bitmap bg = Bitmap.createBitmap(720, 1280, Bitmap.Config.ARGB_8888);

//Setting the Bitmap as background for the ImageView

ImageView i = (ImageView) findViewById(R.id.imageView);

i.setBackgroundDrawable(new BitmapDrawable(bg));

//Creating the Canvas Object

Canvas canvas = new Canvas(bg);

//Creating the Paint Object and set its color & TextSize

Paint paint = new Paint();

49
paint.setColor(Color.BLUE);

paint.setTextSize(50);

//To draw a Rectangle

canvas.drawText("Rectangle", 420, 150, paint);

canvas.drawRect(400, 200, 650, 700, paint);

//To draw a Circle

canvas.drawText("Circle", 120, 150, paint);

canvas.drawCircle(200, 350, 150, paint);

//To draw a Square

canvas.drawText("Square", 120, 800, paint);

canvas.drawRect(50, 850, 350, 1150, paint);

//To draw a Line

canvas.drawText("Line", 480, 800, paint);

canvas.drawLine(520, 850, 520, 1150, paint);}}

OUTPUT:

50
Practical 14 : Develop an Android application that makes use of
Database
Code for Activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>

<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_x="50dp"

android:layout_y="20dp"

android:text="Student Details"

android:textSize="30sp" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_x="20dp"

android:layout_y="110dp"

android:text="Enter Rollno:"

android:textSize="20sp" />

<EditText

android:id="@+id/Rollno"

android:layout_width="150dp"

android:layout_height="wrap_content"

android:layout_x="175dp"

51
android:layout_y="100dp"

android:inputType="number"

android:textSize="20sp" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_x="20dp"

android:layout_y="160dp"

android:text="Enter Name:"

android:textSize="20sp" />

<EditText

android:id="@+id/Name"

android:layout_width="150dp"

android:layout_height="wrap_content"

android:layout_x="175dp"

android:layout_y="150dp"

android:inputType="text"

android:textSize="20sp" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_x="20dp"

android:layout_y="210dp"

android:text="Enter Marks:"

android:textSize="20sp" />

<EditText

52
android:id="@+id/Marks"

android:layout_width="150dp"

android:layout_height="wrap_content"

android:layout_x="175dp"

android:layout_y="200dp"

android:inputType="number"

android:textSize="20sp" />

<Button

android:id="@+id/Insert"

android:layout_width="150dp"

android:layout_height="wrap_content"

android:layout_x="25dp"

android:layout_y="300dp"

android:text="Insert"

android:textSize="30dp" />

<Button

android:id="@+id/Delete"

android:layout_width="150dp"

android:layout_height="wrap_content"

android:layout_x="200dp"

android:layout_y="300dp"

android:text="Delete"

android:textSize="30dp" />

<Button

android:id="@+id/Update"

53
android:layout_width="150dp"

android:layout_height="wrap_content"

android:layout_x="25dp"

android:layout_y="400dp"

android:text="Update"

android:textSize="30dp" />

<Button

android:id="@+id/View"

android:layout_width="150dp"

android:layout_height="wrap_content"

android:layout_x="200dp"

android:layout_y="400dp"

android:text="View"

android:textSize="30dp" />

<Button

android:id="@+id/ViewAll"

android:layout_width="200dp"

android:layout_height="wrap_content"

android:layout_x="100dp"

android:layout_y="500dp"

android:text="View All"

android:textSize="30dp" />

</AbsoluteLayout>

Code for MainActivity.java:

package com.example.exno5;

import android.app.Activity;

54
import android.app.AlertDialog.Builder;

import android.content.Context;

import android.database.Cursor;

import android.database.sqlite.SQLiteDatabase;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.EditText;

public class MainActivity extends Activity implements OnClickListener

EditText Rollno,Name,Marks;

Button Insert,Delete,Update,View,ViewAll;

SQLiteDatabase db;

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

Rollno=(EditText)findViewById(R.id.Rollno);

Name=(EditText)findViewById(R.id.Name);

Marks=(EditText)findViewById(R.id.Marks);

Insert=(Button)findViewById(R.id.Insert);

Delete=(Button)findViewById(R.id.Delete);

Update=(Button)findViewById(R.id.Update);

55
View=(Button)findViewById(R.id.View);

ViewAll=(Button)findViewById(R.id.ViewAll);

Insert.setOnClickListener(this);

Delete.setOnClickListener(this);

Update.setOnClickListener(this);

View.setOnClickListener(this);

ViewAll.setOnClickListener(this);

// Creating database and table

db=openOrCreateDatabase("StudentDB", Context.MODE_PRIVATE, null);

db.execSQL("CREATE TABLE IF NOT EXISTS student(rollno VARCHAR,name


VARCHAR,marks VARCHAR);");

public void onClick(View view)

// Inserting a record to the Student table

if(view==Insert)

// Checking for empty fields

if(Rollno.getText().toString().trim().length()==0||

Name.getText().toString().trim().length()==0||

Marks.getText().toString().trim().length()==0)

showMessage("Error", "Please enter all values");

return;

db.execSQL("INSERT INTO student VALUES('"+Rollno.getText()+"','"+Name.getText()+

"','"+Marks.getText()+"');");

56
showMessage("Success", "Record added");

clearText();

// Deleting a record from the Student table

if(view==Delete)

// Checking for empty roll number

if(Rollno.getText().toString().trim().length()==0)

showMessage("Error", "Please enter Rollno");

return;

Cursor c=db.rawQuery("SELECT * FROM student WHERE rollno='"+Rollno.getText()+"'",


null);

if(c.moveToFirst())

db.execSQL("DELETE FROM student WHERE rollno='"+Rollno.getText()+"'");

showMessage("Success", "Record Deleted");

else

showMessage("Error", "Invalid Rollno");

clearText();

// Updating a record in the Student table

if(view==Update)

57
{

// Checking for empty roll number

if(Rollno.getText().toString().trim().length()==0)

showMessage("Error", "Please enter Rollno");

return;

Cursor c=db.rawQuery("SELECT * FROM student WHERE rollno='"+Rollno.getText()+"'",


null);

if(c.moveToFirst()) {

db.execSQL("UPDATE student SET name='" + Name.getText() + "',marks='" +


Marks.getText() +

"' WHERE rollno='"+Rollno.getText()+"'");

showMessage("Success", "Record Modified");

else {

showMessage("Error", "Invalid Rollno");

clearText();

// Display a record from the Student table

if(view==View)

// Checking for empty roll number

if(Rollno.getText().toString().trim().length()==0)

showMessage("Error", "Please enter Rollno");

58
return;

Cursor c=db.rawQuery("SELECT * FROM student WHERE rollno='"+Rollno.getText()+"'",


null);

if(c.moveToFirst())

Name.setText(c.getString(1));

Marks.setText(c.getString(2));

else

showMessage("Error", "Invalid Rollno");

clearText();

// Displaying all the records

if(view==ViewAll)

Cursor c=db.rawQuery("SELECT * FROM student", null);

if(c.getCount()==0)

showMessage("Error", "No records found");

return;

StringBuffer buffer=new StringBuffer();

while(c.moveToNext())

59
buffer.append("Rollno: "+c.getString(0)+"\n");

buffer.append("Name: "+c.getString(1)+"\n");

buffer.append("Marks: "+c.getString(2)+"\n\n");

showMessage("Student Details", buffer.toString());

public void showMessage(String title,String message)

Builder builder=new Builder(this);

builder.setCancelable(true);

builder.setTitle(title);

builder.setMessage(message);

builder.show();

public void clearText()

Rollno.setText("");

Name.setText("");

Marks.setText("");

Rollno.requestFocus();

60
OUTPUT:

61
62
Practical 15 : Develop an Android application that creates Alarm
Clock
Code for Activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical">

     <TimePicker

        android:id="@+id/timePicker"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_gravity="center" />

     <ToggleButton

        android:id="@+id/toggleButton"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_gravity="center"

        android:layout_margin="20dp"

        android:checked="false"

        android:onClick="OnToggleClicked" />

 </LinearLayout>

63
Code for AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.exno11" >

     <application

        android:allowBackup="true"

        android:icon="@mipmap/ic_launcher"

        android:label="@string/app_name"

        android:supportsRtl="true"

        android:theme="@style/AppTheme" >

        <activity android:name=".MainActivity" >

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

                 <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

        <receiver android:name=".AlarmReceiver" >

        </receiver>

    </application>

</manifest>

64
Code for MainActivity.java:

package com.example.exno11;

 import android.app.AlarmManager;

import android.app.PendingIntent;

import android.content.Intent;

import android.os.Bundle;

import android.support.v7.app.AppCompatActivity;

import android.view.View;

import android.widget.TimePicker;

import android.widget.Toast;

import android.widget.ToggleButton;

import java.util.Calendar;

public class MainActivity extends AppCompatActivity

    TimePicker alarmTimePicker;

    PendingIntent pendingIntent;

    AlarmManager alarmManager;

     @Override

    protected void onCreate(Bundle savedInstanceState)

    {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        alarmTimePicker = (TimePicker) findViewById(R.id.timePicker);

        alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

    }

    public void OnToggleClicked(View view)

65
    {

        long time;

        if (((ToggleButton) view).isChecked())

        {

            Toast.makeText(MainActivity.this, "ALARM ON", Toast.LENGTH_SHORT).show();

            Calendar calendar = Calendar.getInstance();

            calendar.set(Calendar.HOUR_OF_DAY, alarmTimePicker.getCurrentHour());

            calendar.set(Calendar.MINUTE, alarmTimePicker.getCurrentMinute());

            Intent intent = new Intent(this, AlarmReceiver.class);

            pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);

             time=(calendar.getTimeInMillis()-(calendar.getTimeInMillis()%60000));

            if(System.currentTimeMillis()>time)

            {

                if (calendar.AM_PM == 0)

                    time = time + (1000*60*60*12);

                else

                    time = time + (1000*60*60*24);

            }

            alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, time, 10000, pendingIntent);

        }

        else

        {

            alarmManager.cancel(pendingIntent);

            Toast.makeText(MainActivity.this, "ALARM OFF", Toast.LENGTH_SHORT).show();

        }

    }}

66
Code for AlarmReceiver.java:

package com.example.exno11;

 import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;

import android.media.Ringtone;

import android.media.RingtoneManager;

import android.net.Uri;

import android.widget.Toast;

 public class AlarmReceiver extends BroadcastReceiver

    @Override

    public void onReceive(Context context, Intent intent)

    {

        Toast.makeText(context, "Alarm! Wake up! Wake up!", Toast.LENGTH_LONG).show();

        Uri alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);

        if (alarmUri == null)

        {

            alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        }

        Ringtone ringtone = RingtoneManager.getRingtone(context, alarmUri);

        ringtone.play();

    }

67
OUTPUT:

68

You might also like