Android Full
Android Full
RESOURCES
AIM:
To create a android application to understand the Resources.
PROCEDURE:
1. Creating a New App:
2. Open Android Studio and then click on File -> New -> New project
3. Then select the Empty Activity and click Next.
4. Then type the Application name as “resources” and click Next.
5. Then select the language Java and Minimum API Level Android5.1(Lollipop) and
click Next.
6. Finally click Finish.
7. It will take some time to build and load the project.
8. Click on app -> res -> layout -> activity_main.xml. Design a app using Tools.
9. Click on app -> java -> com.example.exno1-> MainActivity.
10. Run the App.
PROGRAM CODE:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context=".MainActivity">
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Your Name" />
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="Name"
android:inputType="textPersonName" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="send" />
</LinearLayout>
Main Activity.java
package com.example.resource;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
OUTPUT
RESULT
Thus the above Android App has been executed and installed successfully.
2.LAYOUTS
AIM:
To create a android application to understand the layouts.
PROCEDURE:
1. Creating a New App:
2. Open Android Studio and then click on File -> New -> New project
3. Then select the Empty Activity and click Next.
4. Then type the Application name as “layout” and click Next.
5. Then select the language Java and Minimum API Level Android5.1(Lollipop) and
click Next.
6. Finally click Finish.
7. It will take some time to build and load the project.
8. Click on app -> res -> layout -> activity_main.xml. Design a app using Tools.
9. Click on app -> java -> com.example.exno1-> MainActivity.
10. Run the App.
PROGRAM CODE:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
<TextView
android:layout_column="1"
android:text="Open..."
android:padding="3dip" />
<TextView
android:text="Ctrl-O"
android:gravity="right"
android:padding="3dip" />
</TableRow>
<TableRow>
<TextView
android:layout_column="1"
android:text="Save..."
android:padding="3dip" />
<TextView
android:text="Ctrl-S"
android:gravity="right"
android:padding="3dip" />
</TableRow>
<TableRow>
<TextView
android:layout_column="1"
android:text="Save As..."
android:padding="3dip" />
<TextView
android:text="Ctrl-Shift-S"
android:gravity="right"
android:padding="3dip" />
</TableRow>
<View
android:layout_height="2dip"
android:background="#FF909090" />
</TableLayout>
Main Activity.java
package com.example.layout;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
OUTPUT
RESULT
Thus the above Android App has been executed and installed successfully.
3. INTENT
AIM:
To create a android application to understand the Intent.
PROCEDURE:
1. Creating a New App:
2. Open Android Studio and then click on File -> New -> New project
3. Then select the Empty Activity and click Next.
4. Then type the Application name as “intent” and click Next.
5. Then select the language Java and Minimum API Level Android5.1(Lollipop) and
click Next.
6. Finally click Finish.
7. It will take some time to build and load the project.
8. Click on app -> res -> layout -> activity_main.xml. Design a app using Tools.
9. Click on app -> java -> com.example.exno1-> MainActivity. To Write java coding for
intent.
10. Run the App.
PROGRAM CODE:
MainActivity.java
package com.example.intent;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
Button button;
EditText editText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = findViewById(R.id.button);
editText = findViewById(R.id.editText);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String url=editText.getText().toString();
Intent intent=new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
}
});
}
}
activity_main.xml
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="99dp"
android:layout_marginLeft="99dp"
android:layout_marginTop="131dp"
android:layout_marginEnd="99dp"
android:layout_marginRight="99dp"
android:layout_marginBottom="65dp"
android:ems="10"
android:inputType="textEmailAddress"
app:layout_constraintBottom_toTopOf="@+id/button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="VISIT"
tools:layout_editor_absoluteX="161dp"
tools:layout_editor_absoluteY="241dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
OUTPUT
RESULT
Thus the above Android App has been executed and installed successfully.
4. USER INTERFACES
AIM:
To create a android application to understand the User Interface.
PROCEDURE:
1. Creating a New App:
2. Open Android Studio and then click on File -> New -> New project
3. Then select the Empty Activity and click Next.
4. Then type the Application name as “sui” and click Next.
5. Then select the language Java and Minimum API Level Android5.1(Lollipop) and
click Next.
6. Finally click Finish.
7. It will take some time to build and load the project.
8. Click on app -> res -> layout -> activity_main.xml. Design a app using Tools.
9. Create another XML file name as “Activity_message.xml”. Design a app page using
Tools.
10. Click on app -> java -> com.example.exno1-> MainActivity. To Write java coding for
user interface.
11. Create another java file name as “MessageActivity.java”. To write java coding for
activity.
12. Run the App.
PROGRAM CODE:
MainActivity.java
package com.example.sui;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void sendMessage(View view)
{
Intent intent= new Intent(this,MessageActivity.class);
startActivity(intent);
}
}
MessageActivity.java
package com.example.sui;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MessageActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_message);
}
}
activity_main.xml
<EditText
android:id="@+id/editText"
android:layout_width="213dp"
android:layout_height="45dp"
android:layout_marginStart="24dp"
android:layout_marginLeft="24dp"
android:layout_marginTop="132dp"
android:ems="10"
android:hint="@string/edit_message"
android:inputType="textPersonName"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:onClick="sendMessage"
android:text="@string/button_label"
app:layout_constraintBaseline_toBaselineOf="@+id/editText"
app:layout_constraintStart_toEndOf="@+id/editText" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="20dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
Activity_message.xml
<TextView
android:id="@+id/textView"
android:layout_width="285dp"
android:layout_height="25dp"
android:text="@string/welcome_message"
android:textColor="@color/colorAccent"
android:textColorLink="@color/colorAccent"
android:textSize="18sp"
tools:layout_editor_absoluteX="42dp"
tools:layout_editor_absoluteY="255dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
String.xml
<resources>
<string name="app_name">Simple User Interface </string>
<string name="edit_message">Enter a Message</string>
<string name="button_label">Send Message</string>
<string name="welcome_message">Welcome to Message Activity</string>
</resources>
OUTPUT
RESULT
Thus the above Android App has been executed and installed successfully.
5.ANIMATION
AIM:
To create a android application Using Animation.
PROCEDURE:
1. Creating a New App:
2. Open Android Studio and then click on File -> New -> New project
3. Then select the Empty Activity and click Next.
4. Then type the Application name as “myanimation” and click Next.
5. Then select the language Java and Minimum API Level Android5.1(Lollipop) and
click Next.
6. Finally click Finish.
7. It will take some time to build and load the project.
8. Click on app -> res -> layout -> activity_main.xml. Design a app using Tools.
9. Create another XML file name as “mixes_anim.xml”. to set scale and rotate properties
values.
10. Click on app -> java -> com.example.exno1-> MainActivity. To Write java coding for
animation.
11. Run the App.
PROGRAM CODE:
Activity_main.xml
<Button
android:id="@+id/android1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Inside Android" />
</RelativeLayout>
MainActivity.java
package com.example.myanimation;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
AndroigManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myanimation">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
AIM:
To create a android application to understand the use of android SQLite.
PROCEDURE:
1. Creating a New App:
2. Open Android Studio and then click on File -> New -> New project
3. Then select the Empty Activity and click Next.
4. Then type the Application name as “mydb” and click Next.
5. Then select the language Java and Minimum API Level Android5.1(Lollipop) and
click Next.
6. Finally click Finish.
7. It will take some time to build and load the project.
8. Click on app -> java -> com.example.exno1-> MainActivity. To Write java coding for
sqlite program.
9. Click on app -> java -> com.example.exno1-> Contact. To Write java coding for
database function.
10. Click on app -> java -> com.example.exno1-> DatabaseHandler. To Write java coding
for database creation.
11. Run the App.
PROGRAM CODE:
Contact.java
package com.example.mydb;
DatabaseHandler.java
package com.example.mydb;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import java.util.ArrayList;
import java.util.List;
public class DatabaseHandler extends SQLiteOpenHelper{
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "contactsManager";
private static final String TABLE_CONTACTS = "contacts";
private static final String KEY_ID = "id";
private static final String KEY_NAME = "name";
private static final String KEY_PH_NO = "phone_number";
public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
//3rd argument to be passed is CursorFactory instance
}
// Creating Tables
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_CONTACTS +
"("+ KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT," +
KEY_PH_NO + " TEXT" + ")";
db.execSQL(CREATE_CONTACTS_TABLE);
}
// Upgrading database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop older table if existed
db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACTS);
// Create tables again
onCreate(db);
}
// code to add the new contact
void addContact(Contact contact) {
SQLiteDatabase db =
this.getWritableDatabase(); ContentValues
values = new ContentValues();
values.put(KEY_NAME, contact.getName()); // Contact Name
values.put(KEY_PH_NO, contact.getPhoneNumber()); // Contact Phone
// Inserting Row
db.insert(TABLE_CONTACTS, null, values);
//2nd argument is String containing nullColumnHack
db.close(); // Closing database connection
}
// code to get the single contact
Contact getContact(int id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_CONTACTS, new String[] { KEY_ID,
KEY_NAME, KEY_PH_NO }, KEY_ID + "=?",
new String[] { String.valueOf(id) }, null, null, null, null);
if (cursor != null)
cursor.moveToFirst();
package com.example.mydb;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import java.util.List;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DatabaseHandler db = new DatabaseHandler(this);
// Inserting Contacts
Log.d("Insert: ", "Inserting ..");
db.addContact(new Contact("AMMU", "919345678012"));
db.addContact(new Contact("BANU", "919999999678"));
db.addContact(new Contact("MANI", "9526622222"));
db.addContact(new Contact("KALAI", "9533333677"));
// Reading all contacts
Log.d("Reading: ", "Reading all contacts..");
List<Contact> contacts = db.getAllContacts();
for (Contact cn : contacts) {
String log = "Id: " + cn.getID() + " ,Name: " + cn.getName() + " ,Phone: " +
cn.getPhoneNumber();
// Writing Contacts to log
Log.d("Name: ", log);
}
}
}
OUTPUT
RESULT
Thus the above Android App has been executed and installed successfully.
7.CALCULATOR
AIM:
To create a android application Using Calculator.
PROCEDURE:
1. Creating a New App:
2. Open Android Studio and then click on File -> New -> New project
3. Then select the Empty Activity and click Next.
4. Then type the Application name as “calc” and click Next.
5. Then select the language Java and Minimum API Level Android5.1(Lollipop) and
click Next.
6. Finally click Finish.
7. It will take some time to build and load the project.
8. Click on app -> res -> layout -> activity_main.xml. Design a calculator app using
Tools.
9. Click on app -> java -> com.example.exno1-> MainActivity. To Write java coding for
calculator.
10. Run the App.
PROGRAM CODE:
Activity_main.xml
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/edt1"/>
<Button
android:id="@+id/buttondiv" style="?
android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/buttonmul"
android:layout_alignStart="@+id/buttonmul"
android:layout_alignLeft="@+id/buttonmul"
android:layout_alignEnd="@+id/buttonmul"
android:layout_alignRight="@+id/buttonmul"
android:layout_marginStart="0dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:layout_marginEnd="0dp"
android:layout_marginRight="0dp"
android:text="/" />
<Button
android:id="@+id/button2" style="?
android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/button1"
android:layout_marginTop="0dp"
android:layout_toStartOf="@+id/button3"
android:layout_toLeftOf="@+id/button3"
android:text="2" />
<Button
android:id="@+id/button3" style="?
android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/button2"
android:layout_centerHorizontal="true"
android:text="3" />
<Button
android:id="@+id/button4" style="?
android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button1"
android:layout_marginRight="0dp"
android:layout_toLeftOf="@+id/button2"
android:text="4" />
<Button
android:id="@+id/button1" style="?
android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/edt1"
android:layout_alignEnd="@+id/button4"
android:layout_alignRight="@+id/button4"
android:layout_marginTop="86dp"
android:layout_marginEnd="0dp"
android:layout_marginRight="0dp"
android:layout_toStartOf="@+id/button4"
android:layout_toLeftOf="@+id/button4"
android:text="1" />
<Button
android:id="@+id/button5" style="?
android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/button2"
android:layout_alignLeft="@+id/button2"
android:layout_alignBottom="@+id/button4"
android:layout_marginStart="0dp"
android:layout_marginLeft="0dp"
android:layout_marginBottom="0dp"
android:text="5" />
<Button
android:id="@+id/button6" style="?
android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button3"
android:layout_alignStart="@+id/button3"
android:layout_alignLeft="@+id/button3"
android:layout_marginStart="0dp"
android:layout_marginLeft="0dp"
android:text="6" />
<Button
android:id="@+id/button7" style="?
android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button4"
android:layout_marginRight="0dp"
android:layout_toLeftOf="@+id/button2"
android:text="7" />
<Button
android:id="@+id/button8" style="?
android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button5"
android:layout_alignStart="@+id/button5"
android:layout_alignLeft="@+id/button5"
android:text="8" />
<Button
android:id="@+id/button9" style="?
android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button6"
android:layout_alignStart="@+id/button6"
android:layout_alignLeft="@+id/button6"
android:layout_marginStart="0dp"
android:layout_marginLeft="0dp"
android:text="9" />
<Button
android:id="@+id/button10" style="?
android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button7"
android:layout_marginTop="0dp"
android:layout_marginRight="0dp"
android:layout_toLeftOf="@+id/button2"
android:text="." />
<Button
android:id="@+id/button0" style="?
android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button8"
android:layout_alignStart="@+id/button8"
android:layout_alignLeft="@+id/button8"
android:layout_marginStart="0dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:text="0" />
<Button
android:id="@+id/buttonC" style="?
android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button9"
android:layout_alignStart="@+id/button9"
android:layout_alignLeft="@+id/button9"
android:layout_marginStart="0dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:text="C" />
<Button
android:id="@+id/buttonmul" style="?
android:attr/buttonStyleSmall"
android:layout_width="98dp"
android:layout_height="wrap_content"
android:layout_below="@+id/buttonsub"
android:layout_alignStart="@+id/buttonsub"
android:layout_alignLeft="@+id/buttonsub"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginStart="0dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:layout_marginEnd="60dp"
android:layout_marginRight="60dp"
android:text="*" />
<Button
android:id="@+id/buttonsub" style="?
android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/buttonadd"
android:layout_alignStart="@+id/buttonadd"
android:layout_alignLeft="@+id/buttonadd"
android:layout_alignEnd="@+id/buttonadd"
android:layout_alignRight="@+id/buttonadd"
android:layout_marginStart="0dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:layout_marginEnd="0dp"
android:layout_marginRight="0dp"
android:text="-" />
<Button
android:id="@+id/buttonadd" style="?
android:attr/buttonStyleSmall"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/button3"
android:layout_alignEnd="@+id/edt1"
android:layout_alignRight="@+id/edt1"
android:layout_marginStart="46dp"
android:layout_marginLeft="46dp"
android:layout_marginTop="0dp"
android:layout_marginEnd="58dp"
android:layout_marginRight="58dp"
android:layout_toRightOf="@+id/button3"
android:text="+" />
<Button
android:id="@+id/buttoneql"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button0"
android:layout_alignStart="@+id/button10"
android:layout_alignLeft="@+id/button10"
android:layout_alignEnd="@+id/buttondiv"
android:layout_alignRight="@+id/buttondiv"
android:layout_marginStart="0dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="37dp"
android:layout_marginEnd="0dp"
android:layout_marginRight="0dp"
android:text="=" />
</RelativeLayout>
MainActivity.java
package com.example.calc;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
Button button0, button1, button2, button3, button4, button5, button6,
button7, button8, button9, buttonAdd, buttonSub, buttonDivision,
buttonMul, button10, buttonC, buttonEqual;
EditText edt1;
float mValueOne, mValueTwo;
boolean mAddition, mSubtract, mMultiplication, mDivision;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button0 = (Button) findViewById(R.id.button0);
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button3 = (Button) findViewById(R.id.button3);
button4 = (Button) findViewById(R.id.button4);
button5 = (Button) findViewById(R.id.button5);
button6 = (Button) findViewById(R.id.button6);
button7 = (Button) findViewById(R.id.button7);
button8 = (Button) findViewById(R.id.button8);
button9 = (Button) findViewById(R.id.button9);
button10 = (Button) findViewById(R.id.button10);
buttonAdd = (Button) findViewById(R.id.buttonadd);
buttonSub = (Button) findViewById(R.id.buttonsub);
buttonMul = (Button) findViewById(R.id.buttonmul);
buttonDivision = (Button) findViewById(R.id.buttondiv);
buttonC = (Button) findViewById(R.id.buttonC);
buttonEqual = (Button) findViewById(R.id.buttoneql);
edt1 = (EditText) findViewById(R.id.edt1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText() + "1");
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText() + "2");
}
});
button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText() + "3");
}
});
button4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText() + "4");
}
});
button5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText() + "5");
}
});
button6.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText() + "6");
}
});
button7.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText() + "7");
}
});
button8.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText() + "8");
}
});
button9.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText() + "9");
}
});
button0.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText() + "0");
}
});
buttonAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (edt1 == null) {
edt1.setText("");
} else {
mValueOne = Float.parseFloat(edt1.getText() + "");
mAddition = true;
edt1.setText(null);
}
}
});
buttonSub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mValueOne = Float.parseFloat(edt1.getText() + "");
mSubtract = true;
edt1.setText(null);
}
});
buttonMul.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mValueOne = Float.parseFloat(edt1.getText() + "");
mMultiplication = true;
edt1.setText(null);
}
});
buttonDivision.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mValueOne = Float.parseFloat(edt1.getText() + "");
mDivision = true;
edt1.setText(null);
}
});
buttonEqual.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mValueTwo = Float.parseFloat(edt1.getText() + "");
if (mAddition == true) {
if (mSubtract == true) {
edt1.setText(mValueOne - mValueTwo + "");
mSubtract = false;
}
if (mMultiplication == true) {
edt1.setText(mValueOne * mValueTwo + "");
mMultiplication = false;
}
if (mDivision == true) {
edt1.setText(mValueOne / mValueTwo + "");
mDivision = false;
}
}
});
buttonC.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText("");
}
});
button10.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText() + ".");
}
});
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.calc">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
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>
</application>
</manifest>
OUTPUT
RESULT
Thus the above Android App has been executed and installed successfully.
8. ANDROID WORKING WITH CAMERA
AIM:
To create a android application to understand the use of android Camera.
PROCEDURE:
1. Creating a New App:
2. Open Android Studio and then click on File -> New -> New project
3. Then select the Empty Activity and click Next.
4. Then type the Application name as “mycamera” and click Next.
5. Then select the language Java and Minimum API Level Android5.1(Lollipop) and
click Next.
6. Finally click Finish.
7. It will take some time to build and load the project.
8. Click on app -> res -> layout -> activity_main.xml. Design a app using Tools.
9. Click on app -> java -> com.example.exno1-> MainActivity. To Write java coding for
camera.
10. Run the App.
PROGRAM CODE:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mycamera">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="81dp"
android:layout_marginTop="54dp"
android:text="Button" />
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.mycamera;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
9.LIST_VIEW
AIM:
To create a android application to understand the use of android List View.
PROCEDURE:
1. Creating a New App:
2. Open Android Studio and then click on File -> New -> New project
3. Then select the Empty Activity and click Next.
4. Then type the Application name as “list” and click Next.
5. Then select the language Java and Minimum API Level Android5.1(Lollipop) and
click Next.
6. Finally click Finish.
7. It will take some time to build and load the project.
8. Click on app -> res -> layout -> activity_main.xml. Design a app using Tools.
9. Create another XML file name as “Activity_listviex.xml”. to set List view properties
values
10. Click on app -> java -> com.example.exno1-> MainActivity. To Write java coding for
list.
11. Run the App.
PROGRAM CODE:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<ListView
android:id="@+id/mobile_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
MainActivity.java File
package com.example.list;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MainActivity extends AppCompatActivity {
String[] mobileArray = {"Android","IPhone","WindowsMobile","Blackberry",
"WebOS","Ubuntu","Windows7","Max OS X"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
string.xml File
<resources>
<string name="app_name">ListDisplay</string>
<string name="action_settings">Settings</string>
</resources>
Activity_listviex.xml File
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:textSize="16dip"
android:textStyle="bold" >
</TextView>
OUTPUT
RESULT
Thus the above Android App has been executed and installed successfully.
AIM:
To create a android application Using Google Map.
PROCEDURE:
1. Creating a New App:
2. Open Android Studio and then click on File -> New -> New project
3. Then select the Google Map Activity and click Next.
4. Then type the Application name as “googlemapapp” and click Next.
5. Then select the language Java and Minimum API Level Android5.1(Lollipop) and
click Next.
6. Finally click Finish.
7. It will take some time to build and load the project.
8. Click on app -> res -> layout -> Goodle_maps_api.xml.
9. Create another XML file name as “Activity_listviex.xml”. to set List view properties
values
10. Click on app -> java -> com.example.exno1-> MapsActivity. To Write java coding
for google Map.
11. Run the App.
PROGRAM CODE:
Goodle_maps_api.xml
<resources>
<!--
TODO: Before you run your application, you need a Google Maps API key.
To get one, follow this link, follow the directions and press "Create" at the end:
https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyTyp
e=CLIENT_SIDE_ANDROID&r=82:15:2F:6F:A8:94:F3:0B:AA:F2:0A:B0:84:7B:5D:20:EE:6
B:E1:20%3Bcom.example.googlemapapp
You can also add your credentials to an existing key, using these values:
Package name:
82:15:2F:6F:A8:94:F3:0B:AA:F2:0A:B0:84:7B:5D:20:EE:6B:E1:20
Once you have your key (it starts with "AIza"), replace the "google_maps_key"
string in this file.
-->
<string name="google_maps_key" templateMergeStrategy="preserve"
translatable="false"> AIzaSyAAwOxsISiSPQgkVUY1e7E-GeuSYQ5DXwY
</string>
</resources>
MapsActivity.java
package com.example.googlemapapp;
import androidx.fragment.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
LatLng sydney = new LatLng(11.617234, 78.565520);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in A.E.T.
College"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is
used
to sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
String.xml
<resources>
<string name="app_name">GoogleMapApp</string>
<string name="title_activity_maps">Map</string>
</resources>
OUTPUT
RESULT
Thus the above Android App has been executed and installed successfully.