Mobile Communication 1701109
Mobile Communication 1701109
Mobile Communication 1701109
EX NO 1
STUDY ON ANDROID AND ANDROID STUDIO
DATE:
6.12.19
AIM:
To study about Android and Android Studio in detail.
ANDROID:
Introduction:
Android is a mobile operating system based on a modified version of the Linux kernel and
other open source software, designed primarily for touchscreen mobile devices such
as smartphones and tablets. Android is developed by a consortium of developers known as
the Open Handset Alliance, with the main contributor and commercial marketer being Google.
Initially developed by Android Inc., which Google bought in 2005, Android was unveiled
in 2007, with the first commercial Android device launched in September 2008. The current
stable version is Android 10, released on September 3, 2019. The core Android source code is
known as Android Open Source Project (AOSP), which is primarily licensed under the Apache
License. This has allowed variants of Android to be developed on a range of other electronics,
such as game consoles, digital cameras, PCs,Android TV for televisions and Android Wear
OS for wearables.
Features of Android:
Android is a powerful operating system competing with Apple 4GS and supports great
features. Few of them are listed below
1) Beautiful UI
Android OS basic screen provides a beautiful and intuitive user interface.
2) Connectivity
GSM/EDGE, IDEN, CDMA, EV-DO, UMTS, Bluetooth, Wi-Fi, LTE, NFC and
WiMAX.
3) Storage
SQLite, a lightweight relational database, is used for data storage purposes.
4) Mediasupport
H.263, H.264, MPEG-4 SP, AMR, AMR-WB, AAC, HE-AAC, AAC 5.1, MP3, MIDI,
OggVorbis, WAV, JPEG, PNG, GIF, and BMP.
5) Messaging
SMS and MMS
6) Webbrowser
Based on the open-source WebKit layout engine, coupled with Chrome's V8 JavaScript
engine supporting HTML5 and CSS3.
7) Multi-touch
Android has native support for multi-touch which was initially made available in
handsets such as the HTC Hero.
8) Multi-tasking
User can jump from one task to another and same time various application can run
simultaneously.
1701109
9) Resizablewidgets
Widgets are resizable, so users can expand them to show more content or shrink them
to save space.
10) Multi-Language
Supports single direction and bi-directional text.
11) GCM
Google Cloud Messaging (GCM) is a service that lets developers send short message
data to theirusers on Android devices, without needing a proprietary sync solution.
12) Wi-FiDirect
A technology that lets apps discover and pair directly, over a high-bandwidth peer-to-
peer connection.
13) AndroidBeam
A popular NFC-based technology that lets users instantly share, just by touching two
NFC-enabled phones together.
Architecture:
Android operating system is a stack of software components which is roughly divided into
five sections and four main layers as shown below in the architecture diagram.
Applications
Application Framework
Android
Libraries Runtime
Linux Kernel
1) Linux kernel
At the bottom of the layers is Linux. This provides a level of abstraction between the
device hardware and it contains all the essential hardware drivers.
2) Libraries
On top of Linux kernel there is a set of libraries such as Surface Manager, Media
Framework,WebKit (open-source Web browser engine), Libc (a well-known library),
SQLite (database), SSL libraries (for Internet security), etc.
Android Libraries encompass Java-based libraries specific to Android development.
Examples of libraries in this category include the application framework libraries in
addition to those that facilitate user interface building, graphics drawing and database
access.
Eg: android.app, android.content, android.database, etc
3) Android Runtime
This section provides a key component called Dalvik Virtual Machine which is a kind of
Java Virtual Machine specially designed and optimized for Android.
It makes use of Linux core features like memory management and multi-threading,
which is intrinsic in the Java language. The Android runtime also provides a set of core
libraries which enable Android application developers to write Android applications
using standard Java programming language.
1701109
4) Application Framework
The Application Framework layer provides many higher-level services to applications in
the form of Java classes. Application developers are allowed to make use of these
services in their applications.
The Android framework includes the following key services −
• Activity Manager − Controls all aspects of the application lifecycle and activity
stack.
• Content Providers − Allows applications to publish and share data with other
applications.
• Resource Manager − Provides access to non-code embedded resources such as
strings, color settings and user interface layouts.
• Notifications Manager − Allows applications to display alerts and notifications
to the user.
• View System − An extensible set of views used to create application user
interfaces.
5) Applications
All the Android applications are at the top layer. The applicationsare installed on this
layer only. Examples of such applications are Contacts Books, Browser, Games etc.
ANDROID STUDIO:
Android Studio is the official integrated development environment (IDE) for Google’s
Android operating system, built on JetBrains' IntelliJ IDEA software and designed specifically
for Android development.It is available for download on Windows, macOS and Linux based
operating systems. It is a replacement for the Eclipse Android Development Tools (ADT) as the
primary IDE for native Android application development.
Android Studio was announced on May 16, 2013 at the Google I/O conference. The first
stable build was released in December 2014, starting from version 1.0.Since May 7,
2019, Kotlin is Google’s preferredlanguage for Android app development.Still, other
programming languages are supported by Android Studio, such as Java and C++.
Features:
1) Gradle-based build support
2) Android-specific refactoring and quick fixes
3) Lint tools to catch performance, usability, version compatibility and other problems
4) ProGuard integration and app-signing capabilities
5) Template-based wizards to create common Android designs and components
6) A rich layout editor that allows users to drag-and-drop UI components, option
to preview layouts on multiple screen configurations
7) Support for building Android Wear apps
8) Built-in support for Google Cloud Platform, enabling integration with Firebase Cloud
Messaging (Earlier 'Google Cloud Messaging') and Google App Engine
9) Android Virtual Device (Emulator) to run and debug apps in the Android studio.
1701109
TOTAL 20
RESULT:
Thus, the study on Android and Android Studio was completed successfully.
1701109
EX NO:2 ANDROID APP FOR LAYOUT GUI COMPONENTS FONTS AND COLORS
DATE:
13.12.19
AIM:
To develop a Simple Android Application that uses GUI components, Font and Colors.
PROCEDURE:
Step 1: Open Android Studio and then click on File -> New -> New project.
Step 2: Then type the Application name as “APP1″ and click Next.
Step 3: Then select the Minimum SDK as shown below and click next.
Step 4: Then select the Empty Activity and click next.
Step 5: Finally click Finish.
Designing layout for the Android Application:
Step1: Click on app -> java -> com.example.app1 -> Main Activity.
Step2: Type the source code for main activity.java.The main coding part is completed.
Step3: Run the application to view the output. Click Run.
SOURCE CODE:
<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>
1701109
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() {
1701109
@Override
public void onClick(View v) {
switch (ch) {
case 1:
t.setTextColor(Color.RED);
break;
case 2:
t.setTextColor(Color.CYAN);
break;
case 3:
t.setTextColor(Color.MAGENTA);
break;
} ch++;
if (ch == 3)
ch = 1;
}
});
}}
1701109
OUTPUT:
TOTAL 20
RESULT:
Thus an application was developed that uses GUI components, fonts and colors and
executed successfully.
1701109
EX NO 3
ANDROID APPLICATION FOR LAYOUT MANAGERS AND EVENT LISTENERS
DATE:
20.12.19
AIM:
To develop a Simple Android Application that uses layout managers and event listeners.
PROCEDURE:
Step 1: Open Android Studio and then click on File -> New -> New project.
Step 2: Then type the Application name as “APP2″ and click Next.
Step 3: Then select the Minimum SDK as shown below and click next.
Step 4: Then select the Empty Activity and click next.
Step 5: Finally click Finish.
Step7: type the activity name as, Second Activity and click finish.
Designing layout for the Android Application:
Step6: Now click on design and the application appears the designing part is completed.
Java Coding for the Android Application:
Step1: Click on app -> java -> com.example.app2 -> Main Activity.
Step2: Type the source code for main activity.java.The main coding part is completed.
Step3: click on app->java->com.example.app2->Second activity
Step4: Run the application to view the output. Click Run.
1701109
SOURCE CODE:
<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"
android:layout_height="match_parent"
android:layout_marginTop="100dp"
1701109
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"/>
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_row="0"
android:layout_column="1"
android:ems="10"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
1701109
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"
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"/>
1701109
<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"
android:text="Submit"/>
</RelativeLayout>
<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"
1701109
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"/>
<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>
1701109
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;
EditText e1,e2;
Button bt;
Spinner s;
String [] dept_array={"CSE","ECE","IT","Mech","Civil"};
String name,reg,dept;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
s= (Spinner) findViewById(R.id.spinner);
//Creating Adapter for Spinner for adapting the data from array to Spinner
s.setAdapter(adapter);
bt.setOnClickListener(new View.OnClickListener() {
@Override
name=e1.getText().toString();
reg=e2.getText().toString();
dept=s.getSelectedItem().toString();
i.putExtra("name_key", name);
i.putExtra("reg_key",reg);
i.putExtra("dept_key", dept);
startActivity(i); }
});
}
1701109
package com.example.exno2;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
//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);
t3.setText(dept);}}
1701109
OUTPUT:
TOTAL 20
RESULT:
Thus an android application was developed that uses layout managers and event listeners
and output was executed successfully.
1701109
EX NO 4
DATE:
27.12.19
AIM:
To develop an android application for native simple calculator and perform various operations
to display the output.
PROCEDURE:
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
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp">
1701109
<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"
1701109
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>
Code for main activity.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;
1701109
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
// 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 = "+";
case R.id.Mul:
oper = "*";
result = num1 * num2;
break;
case R.id.Div:
oper = "/";
default:
break;
}
// form the output line
Result.setText(num1 + " " + oper + " " + num2 + " = " + result);
}
}
OUTPTUT:
1701109
POST VIVA 2
TOTAL 20
RESULT:
EX NO 5
AIM:
To develop a Simple Android Application that draws basic Graphical Primitives on the screen.
PROCEDURE:
OUTPUT:
POST VIVA 2
TOTAL 20
RESULT:
Thus a Simple Android Application that draws basic Graphical Primitives on the screen
is developed and executed successfully.
1701109
EX NO 6
ANDROID APPLICATION THAT MAKES USE OF DATABASE
DATE:
10.1.20
AIM:
PROCEDURE:
<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"
1701109
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"
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"
1701109
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
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"
1701109
<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"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="25dp"
android:layout_y="400dp"
android:text="Update"
android:textSize="30dp" />
<Button
1701109
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>
package com.example.exno5;
import android.app.Activity;
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;
1701109
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
EditText Rollno,Name,Marks;
Button Insert,Delete,Update,View,ViewAll;
SQLiteDatabase db;
@Override
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);
View=(Button)findViewById(R.id.View);
ViewAll=(Button)findViewById(R.id.ViewAll);
Insert.setOnClickListener(this);
Delete.setOnClickListener(this);
Update.setOnClickListener(this);
View.setOnClickListener(this);
1701109
ViewAll.setOnClickListener(this);
if(view==Insert)
if(Rollno.getText().toString().trim().length()==0||
Name.getText().toString().trim().length()==0||
Marks.getText().toString().trim().length()==0)
return;
"','"+Marks.getText()+"');");
clearText();
if(view==Delete)
if(Rollno.getText().toString().trim().length()==0)
return;
if(c.moveToFirst())
else
clearText();
if(view==Update)
if(Rollno.getText().toString().trim().length()==0)
return;
}
1701109
if(c.moveToFirst()) {
else {
clearText();
if(view==View)
if(Rollno.getText().toString().trim().length()==0)
return;
if(c.moveToFirst())
Name.setText(c.getString(1));
Marks.setText(c.getString(2));
1701109
else
clearText();
if(view==ViewAll)
if(c.getCount()==0)
return;
while(c.moveToNext())
buffer.append("Rollno: "+c.getString(0)+"\n");
buffer.append("Name: "+c.getString(1)+"\n");
buffer.append("Marks: "+c.getString(2)+"\n\n");
}
1701109
builder.setCancelable(true);
builder.setTitle(title);
builder.setMessage(message);
builder.show();
Rollno.setText("");
Name.setText("");
Marks.setText("");
Rollno.requestFocus();
}
1701109
OUTPUT:
POST VIVA 2
TOTAL 20
RESULT:
Thus a Simple Android Application that makes use of Database is developed and
executed successfully.
1701109
1701109
1701109
EX NO 7
ANDROID APPLICATION THAT WRITES DATA TO THE SD CARD
DATE:
24.1.20
AIM:
PROCEDURE:
Step1: Open Android Studio and then click on File -> New -> New project.
Step2: Then type the Application name as “app6″ and click Next.
Step3: Then select the Minimum SDK as shown below and click next.
Step4: Then select the Empty Activity and click next.
Step5: Finally click Finish.
Designing layout for the Android Application:
android:layout_height="wrap_content"
android:singleLine="true"
android:textSize="30dp" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Write Data"
android:textSize="30dp" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Read data"
android:textSize="30dp" />
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Clear"
android:textSize="30dp" />
</LinearLayout>
Code for android manifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.exno6"
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<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"
1701109
<intent-filter
</intent-filter></activity></application></manifest>
package com.example.exno9;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
{ EditText e1;
Button write,read,clear;
@Override
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
write.setOnClickListener(new View.OnClickListener()
{ @Override
{ String message=e1.getText().toString();
try
f.createNewFile();
fout.write(message.getBytes());
fout.close();
Toast.makeText(getBaseContext(),"Data Written in
SDCARD",Toast.LENGTH_LONG).show();
} catch (Exception e)
Toast.makeText(getBaseContext(),e.getMessage(),Toast.LENGTH_LONG).show();
});read.setOnClickListener(new View.OnClickListener()
{@Override
{ String message;
1701109
buf += message;
e1.setText(buf);
br.close();
fin.close();
catch (Exception e)
Toast.makeText(getBaseContext(), e.getMessage(),
Toast.LENGTH_LONG).show();
});
clear.setOnClickListener(new View.OnClickListener()
@Override
1701109
e1.setText("");
});
OUTPUT:
1701109
POST VIVA 2
TOTAL 20
RESULT:
Thus an android application was created to write data and fetch to SD card successfully
and output was displayed.
1701109
EX NO 8
DEVELOP AN APPLICATION TO CAPTURE IMAGE USING BUILT IN CAMERA
DATE:
24.1.20
AIM:
CONTENT:
The android framework provides the facility of working with camera in 2 ways:
PROGRAM PROCEDURE:
Step1: create a new project in Android studio. Name it camera code example.
Step2: open res->layout->xml. Type the source code for frame layout.
Step3: open src->package->main activity.java. Load the fragment into fragment layout in main
activity.
SOURCE CODE:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
1701109
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.example.cameracodeexample.Fragments.CameraFragment;
FrameLayout frameLayout;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
transaction.replace(R.id.frameLayout, fragment);
if (bool)
transaction.addToBackStack(null);
transaction.commit();
}}
Camera fragment:
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
1701109
android:text="Save Image"
android:layout_gravity="center"
android:layout_margin="@dimen/_12sdp"
android:textSize="@dimen/_18sdp"
android:textAlignment="center"
android:background="#EBEBEB"/>
TextView
<android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="View Image"
android:layout_gravity="center"
android:layout_margin="@dimen/_12sdp"
android:textSize="@dimen/_18sdp"
android:textAlignment="center"
android:background="#EBEBEB"
android:layout_below="@id/text"/>
camera fragment.java
import android.Manifest;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.sqlite.SQLiteDatabase;
1701109
import android.graphics.Bitmap;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.v4.app.Fragment;
import android.util.Base64;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.example.cameracodeexample.MainActivity;
import com.example.cameracodeexample.R;
import com.example.cameracodeexample.utils.DataBaseHandler;
import java.io.ByteArrayOutputStream;
TextView text,text1;
//Bitmap photo;
String photo;
DataBaseHandler databaseHandler;
Bitmap theImage;
@Nullable
@Override
text = view.findViewById(R.id.text);
text1 = view.findViewById(R.id.text1);
text.setOnClickListener(new View.OnClickListener() {
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
if (getActivity().checkSelfPermission(Manifest.permission.CAMERA) !=
PackageManager.PERMISSION_GRANTED)
{ requestPermissions(new String[]{Manifest.permission.CAMERA},
MY_CAMERA_PERMISSION_CODE);
else
startActivityForResult(cameraIntent, CAMERA_REQUEST);
@Override
});
return view;
db = databaseHandler.getWritableDatabase();
cv.put(databaseHandler.KEY_IMG_URL,photo);
if (id < 0) {
} else {
}@Override
if (requestCode == MY_CAMERA_PERMISSION_CODE)
if (grantResults[0] == PackageManager.PERMISSION_GRANTED)
{
1701109
startActivityForResult(cameraIntent, CAMERA_REQUEST);
else
} @Override
photo=getEncodedString(theImage);
setDataToDataBase();
bitmap.compress(Bitmap.CompressFormat.JPEG,100, os);
bitmap.compress(Bitmap.CompressFormat.PNG, (0–100 compression), os);*/
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
this.context = context;
public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + "(" +
KEY_ID +
public static final String DROP_TABLE = "DROP TABLE IF EXISTS " + TABLE_NAME +
""; @Override
db.execSQL(CREATE_TABLE);}
@Override
db.execSQL(DROP_TABLE);
1701109
onCreate(db);
import android.content.Context;
import android.content.DialogInterface;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.RecyclerView;
import android.util.Base64;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.squareup.picasso.Picasso;
import java.util.ArrayList;
Context context;
ArrayList singleRowArrayList;
SQLiteDatabase db;
DataBaseHandler myDatabase;
1701109
this.context = context;
this.singleRowArrayList = singleRowArrayList;
this.db = db;
this.myDatabase = myDatabase; }
@NonNull
@Override
return myViewHolder;
} @Override
myViewHolder.newsImage.setImageBitmap(getBitmapFromEncodedString(singleRowArrayList
.get(i).image));
myViewHolder.delete.setOnClickListener(new View.OnClickListener() {
@Override
deletedata(i,singleRowArrayList);
});} @Override
return singleRowArrayList.size();
}
1701109
ImageView newsImage,delete;
super(itemView);
new AlertDialog.Builder(context)
.setIcon(R.drawable.defaultimage)
.setTitle("Delete result")
@Override
myDatabase.deleteEntry(singleRowArrayList.get(position).getUid());
singleRowArrayList.remove(position);
notifyItemRemoved(position);
notifyDataSetChanged();
myDatabase.close();
})
.setNegativeButton("No", null)
1701109
.show();
return img; }}
OUTPUT:
POST VIVA 2
TOTAL 20
RESULT:
Thus an android application was created to capture an image using built in camera
successfully.
1701109
AIM:
PROCEDURE:
SOURCE CODE:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Message"
android:textSize="30sp" />
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textSize="30sp" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:layout_gravity="center"
android:text="Notify"
android:textSize="30sp"/>
</LinearLayout>
Code for main activity .java
package com.example.exno10;
import android.app.Notification;
import android.app.NotificationManager;
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.Button;
import android.widget.EditText;
{ Button notify;
EditText e;
1701109
@Override
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
e= (EditText) findViewById(R.id.editText);
notify.setOnClickListener(new View.OnClickListener()
@Override
noti.flags |= Notification.FLAG_AUTO_CANCEL;
manager.notify(0, noti);
});
}
1701109
OUTPUT:
RESULT:
Thus Android Application that creates an alert upon receiving a message is developed and
executed successfully.
1701109
EXNO 10
AIM:
PROCEDURE:
Step1: Open Android Studio and then click on File -> New -> New project.
Step3: Then select the Minimum SDK as shown below and click next.
Step1: Click on File -> New -> Activity -> Empty Activity.
Step2: Type the Activity Name as Alarm Receiver and click Finish button.
Step3: type the source code for activity main.xml where design part will be completed.
Step2: change the activity tag to receiver tag in the AndroidManifest.xml file
Step3: type the source code for android manifest.xml. Changes are done in manifest.
SOURCE CODE:
<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>
1701109
<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" >
<intent-filter>
</intent-filter></activity>
</receiver></application></manifest>
package com.example.exno11;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
1701109
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;
{ TimePicker alarmTimePicker;
PendingIntent pendingIntent;
AlarmManager alarmManager;
@Override
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
long time;
if (((ToggleButton) view).isChecked())
calendar.set(Calendar.HOUR_OF_DAY, alarmTimePicker.getCurrentHour());
calendar.set(Calendar.MINUTE, alarmTimePicker.getCurrentMinute());
time=(calendar.getTimeInMillis()-(calendar.getTimeInMillis()%60000));
if(System.currentTimeMillis()>time)
{ if (calendar.AM_PM == 0)
else
}else
alarmManager.cancel(pendingIntent);
package com.example.exno11;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.Ringtone;
import android.media.RingtoneManager;
1701109
import android.net.Uri;
import android.widget.Toast;
{ @Override
if (alarmUri == null)
{ alarmUri =
RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
ringtone.play();}}
OUTPUT:
1701109
RESULT:
Thus Android Application that creates Alarm Clock is developed and executed successfully.
1701109
EX NO 11
DEMONSTRATE ACTIVITY CLASS TO SHOW DIFFERENT EVENTS
DATE:
14.2.20
AIM:
Step1: Click on app -> java -> com.example.exno 9 -> Main Activity.
SOURCE CODE:
Acitivity 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"
1701109
android:onClick="OnToggleClicked" />
</LinearLayout>
Android manifest.xml:
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;
@Override
protected void onCreate(Bundle savedInstanceState)
{
1701109
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
alarmTimePicker = (TimePicker) findViewById(R.id.timePicker);
alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
}
public void OnToggleClicked(View view)
{
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();
}
}
}
Alarm receiver:
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
1701109
RESULT:
DATE:
21.2.20
AIM:
To develop an android application to demonstrate user to send one app to other app and
display the output.
PROCEDURE:
Step2: type the source code for res layout activity.xml. One type of text is created.
How to run?
1) To run the app from android studio, open one of your projects file activity and click RUN.
4) when you click the default screen, the original application displays as an output.
SOURCE CODE:
code to res/layout/activity_main.xml.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/parent"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:gravity="center"
android:background="#33FFFF00"
1701109
android:orientation="vertical">
<TextView
android:id="@+id/text"
android:textSize="18sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
code to src/MainActivity.java:
package com.example.andy.myapplication;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
TextView textView;
@Override
super.onCreate(savedInstanceState);
setContentView(view);
textView = findViewById(R.id.text);
textView.setOnClickListener(new View.OnClickListener() {
1701109
@Override
Intent launchIntent =
getPackageManager().getLaunchIntentForPackage("com.google.android.youtube"); if
(launchIntent != null) {
startActivity(launchIntent);
} else {
}}});}}
OUTPUT:
1701109
TOTAL 20
RESULT:
Thus an application was developed to send user app to other app and output was
generated successfully.
1701109
EXNO 13
PROGRAM TO PLAY AUDIO AND VIDEO FILES
DATE:
28.2.20
AIM:
To develop an app to play audio/video files or as a media player and display the output.
PROCEDURE:
Step5: run the app from android studio (actual android mobile device is connected with the
computer)
Step6: click RUN from any projects file activity and display the output.
SOURCE CODE:
package com.example.sairamkrishna.myapplication;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
1701109
import java.util.concurrent.TimeUnit;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button) findViewById(R.id.button);
b2 = (Button) findViewById(R.id.button2);
b3 = (Button)findViewById(R.id.button3);
b4 = (Button)findViewById(R.id.button4);
iv = (ImageView)findViewById(R.id.imageView);
tx1 = (TextView)findViewById(R.id.textView2);
tx2 = (TextView)findViewById(R.id.textView3);
tx3 = (TextView)findViewById(R.id.textView4);
tx3.setText("Song.mp3");
seekbar = (SeekBar)findViewById(R.id.seekBar);
seekbar.setClickable(false);
b2.setEnabled(false);
b3.setOnClickListener(new View.OnClickListener() {
@Override
Toast.makeText(getApplicationContext(), "Playing
sound",Toast.LENGTH_SHORT).show();
mediaPlayer.start();
finalTime = mediaPlayer.getDuration();
startTime = mediaPlayer.getCurrentPosition();
if (oneTimeOnly == 0) {
seekbar.setMax((int) finalTime);
oneTimeOnly = 1;
TimeUnit.MILLISECONDS.toMinutes((long) finalTime),
TimeUnit.MILLISECONDS.toSeconds((long) finalTime) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long)
finalTime)))
TimeUnit.MILLISECONDS.toMinutes((long) startTime),
TimeUnit.MILLISECONDS.toSeconds((long) startTime) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long)
startTime))));
seekbar.setProgress((int)startTime);
myHandler.postDelayed(UpdateSongTime,100);
b2.setEnabled(true);
1701109
b3.setEnabled(false);}});
b2.setOnClickListener(new View.OnClickListener() {
@Override
Toast.makeText(getApplicationContext(), "Pausing
sound",Toast.LENGTH_SHORT).show();
mediaPlayer.pause();
b2.setEnabled(false);
b3.setEnabled(true);}});
b1.setOnClickListener(new View.OnClickListener() {
@Override
if((temp+forwardTime)<=finalTime){
mediaPlayer.seekTo((int) startTime);
seconds",Toast.LENGTH_SHORT).show();
}else{
seconds",Toast.LENGTH_SHORT).show();}}});
b4.setOnClickListener(new View.OnClickListener() {
@Override
if((temp-backwardTime)>0){
mediaPlayer.seekTo((int) startTime);
seconds",Toast.LENGTH_SHORT).show();
}else{
seconds",Toast.LENGTH_SHORT).show();}}});}
startTime = mediaPlayer.getCurrentPosition();
TimeUnit.MILLISECONDS.toMinutes((long) startTime),
TimeUnit.MILLISECONDS.toSeconds((long) startTime) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.
toMinutes((long) startTime))));
seekbar.setProgress((int)startTime);
myHandler.postDelayed(this, 100);
}};}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
1701109
android:layout_height="wrap_content"
android:id="@+id/textview"
android:textSize="35dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tutorials point"
android:id="@+id/textView"
android:layout_below="@+id/textview"
android:layout_centerHorizontal="true"
android:textColor="#ff7aff24"
android:textSize="35dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:src="@drawable/abc"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/forward"
android:id="@+id/button"
1701109
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pause"
android:id="@+id/button2"
android:layout_alignParentBottom="true"
android:layout_alignLeft="@+id/imageView"
android:layout_alignStart="@+id/imageView" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/back"
android:id="@+id/button3"
android:layout_alignTop="@+id/button2"
android:layout_toRightOf="@+id/button2"
android:layout_toEndOf="@+id/button2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rewind"
android:id="@+id/button4"
android:layout_alignTop="@+id/button3"
android:layout_toRightOf="@+id/button3"
android:layout_toEndOf="@+id/button3" />
1701109
<SeekBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/seekBar"
android:layout_alignLeft="@+id/textview"
android:layout_alignStart="@+id/textview"
android:layout_alignRight="@+id/textview"
android:layout_alignEnd="@+id/textview"
android:layout_above="@+id/button" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/textView2"
android:layout_above="@+id/seekBar"
android:layout_toLeftOf="@+id/textView"
android:layout_toStartOf="@+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/textView3"
android:layout_above="@+id/seekBar"
android:layout_alignRight="@+id/button4"
android:layout_alignEnd="@+id/button4" />
1701109
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/textView4"
android:layout_alignBaseline="@+id/textView2"
android:layout_alignBottom="@+id/textView2"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<resources>
<string name="back"><![CDATA[<]]></string>
<string name="rewind"><![CDATA[<<]]></string>
<string name="forward"><![CDATA[>>]]></string>
<string name="pause">||</string>
</resources>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sairamkrishna.myapplication" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
1701109
<activity
android:name="com.example.sairamkrishna.myapplication.MainActivity"
android:label="@string/app_name" >
<intent-filter>
</intent-filter>
</activity>
</application>
</manifest>
OUTPUT:
1701109
TOTAL 20
RESULT:
Thus an android app was developed to demonstrate audio/video files and output was
displayed successfully.
1701109
EXNO 14
DEVELOP A PROGRAM TO SEND SMS
DATE:
28.2.20
AIM:
To develop an app to send user SMS and get its reply and to display it as an output.
PROCEDURE:
In Android, you can use SmsManager API or devices Built-in SMS application to send
SMS's.
1) SmsManager API
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
Create->file->new project
Src/com.exmaple.tutorialspoint/main activity.java
Step3:cotent of
Step4: content of
Android manifext.xml
Step6: run the app from android studio (actual mobile device is connected from computer)
1701109
Click RUN from any projects activity files to see the output.
SOURCE CODE:
package com.example.tutorialspoint;
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.telephony.SmsManager;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
Button sendBtn;
EditText txtphoneNo;
1701109
EditText txtMessage;
String phoneNo;
String message;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sendBtn.setOnClickListener(new View.OnClickListener() {
sendSMSMessage();
});
phoneNo = txtphoneNo.getText().toString();
message = txtMessage.getText().toString();
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.SEND_SMS)
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.SEND_SMS)) {
} else {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.SEND_SMS},
MY_PERMISSIONS_REQUEST_SEND_SMS);}}}
1701109
@Override
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_SEND_SMS: {
if (grantResults.length > 0
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(),
return;}}}}}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="MainActivity">
1701109
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="30dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ff87ff09"
android:textSize="30dp"
android:layout_below="@+id/textView1"
android:layout_alignRight="@+id/imageButton"
android:layout_alignEnd="@+id/imageButton" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton"
android:src="@drawable/abc"
android:layout_below="@+id/textView2"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
1701109
android:layout_height="wrap_content"
android:id="@+id/editText"
android:phoneNumber="true"
android:textColorHint="@color/abc_primary_text_material_dark"
android:layout_below="@+id/imageButton"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText2"
android:layout_below="@+id/editText"
android:layout_alignLeft="@+id/editText"
android:layout_alignStart="@+id/editText"
android:textColorHint="@color/abc_primary_text_material_dark"
android:layout_alignRight="@+id/imageButton"
android:layout_alignEnd="@+id/imageButton"
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send Sms"
android:id="@+id/btnSendSMS"
android:layout_below="@+id/editText2"
android:layout_centerHorizontal="true"
android:layout_marginTop="48dp" />
</RelativeLayout>
1701109
<resources>
<string name="app_name">tutorialspoint</string>
</resources>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tutorialspoint" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
<activity
android:name="com.example.tutorialspoint.MainActivity"
android:label="@string/app_name" >
<intent-filter>
</intent-filter></activity></application></manifest>
1701109
OUTPUT:
RESULT:
Thus an android app was developed to send user sms and receive reply. The output was
displayed successfully.
1701109
EXNO 15
AIM:
To develop an android app to convert text to speech and to display the output.
PROCEDURE:
Step1: android provides TEXT TO SPEECH class to instantiates an object of thos class with
specification init listener.
Step2: specify the properties for TEXT TO SPEECH object. Language can be set by calling
set language () method.
Step3: After language setup, call speak () method of the class to speak the text.
PROGRAM PROCEDURE:
Step5: run the app from android studio (actual android mobile device is connected with the
computer)
Click RUN from any projects activity file to see the output.
Step6: after checking the output display screen, type some text field, click on TEXT TO
SPEECH button .a notification would appear and text will be spoken. Do at different location
and you will hear the sound.
1701109
SOURCE CODE:
Code to src/MainActivity.java.
package com.example.sairamkrishna.myapplication;
import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import java.util.Locale;
import android.widget.Toast;
TextToSpeech t1;
EditText ed1;
Button b1;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ed1=(EditText)findViewById(R.id.editText);
b1=(Button)findViewById(R.id.button);
@Override
if(status != TextToSpeech.ERROR) {
t1.setLanguage(Locale.UK);
}}});
1701109
b1.setOnClickListener(new View.OnClickListener() {
@Override
Toast.makeText(getApplicationContext(), toSpeak,Toast.LENGTH_SHORT).show();
}});}
if(t1 !=null){
t1.stop();
t1.shutdown();}
super.onPause();}}
code to activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:transitionGroup="true">
android:layout_height="wrap_content"
android:id="@+id/textview"
android:textSize="35dp"
1701109
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tutorials point"
android:id="@+id/textView"
android:layout_below="@+id/textview"
android:layout_centerHorizontal="true"
android:textColor="#ff7aff24"
android:textSize="35dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/abc"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:theme="@style/Base.TextAppearance.AppCompat" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_below="@+id/imageView"
android:layout_marginTop="46dp"
android:hint="Enter Text"
android:layout_alignParentRight="true"
1701109
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#ff7aff10"
android:textColorHint="#ffff23d1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text to Speech"
android:id="@+id/button"
android:layout_below="@+id/editText"
android:layout_centerHorizontal="true"
android:layout_marginTop="46dp" />
</RelativeLayout>
content of Strings.xml.
<resources>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sairamkrishna.myapplication" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
1701109
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
</intent-filter></activity></application></manifest>
OUTPUT:
1701109
RESULT:
Thus an android app was developed to convert text to speech and output was displayed
successfully.
1701109
EXNO 16
DEVELOP A PROGRAM TO CALL A NUMBER
DATE:
20.3.20
AIM:
To develop an android studio to make a phone call a number and to display an output.
PROCEDURE:
use ACTION_CALL action to trigger built-in phone call functionality available in Android
device
use ACTION_DIAL action instead of ACTION_CALL, in that case you will have option to
modify hardcoded phone number before making a call instead of making a direct call.
To make a phone call at a given number 91-000-000-0000, you need to specify tel: as URI
using setData() method as follows −
phoneIntent.setData(Uri.parse("tel:91-000-000-0000"));
The interesting point is that, to make a phone call, you do not need to specify any extra data
or data type.
Step5: run the app from android studio(actual android mobile device is connected with the
computer)
SOURCE CODE:
package com.example.saira_000.myapplication;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button.setOnClickListener(new View.OnClickListener() {
callIntent.setData(Uri.parse("tel:0377778888"));
if (ActivityCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.CALL_PHONE) !=
PackageManager.PERMISSION_GRANTED) {
return; }
1701109
startActivity(callIntent); }});}}}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/buttonCall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
</LinearLayout>
<resources>
</resources>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.saira_000.myapplication"
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
1701109
android:theme="@style/AppTheme" >
<activity
android:name="com.example.saira_000.myapplication.MainActivity"
android:label="@string/app_name" >
<intent-filter>
</intent-filter> </activity></application></manifest>
OUTPUT:
1701109
TOTAL 20
RESULT:
Thus an android app was developed to call a number and output as displayed
successfully.