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

Mad Lab Programs

The document describes developing an Android application using intents and controls. It includes: 1. Developing two activities - a main activity to enter data and a second activity to display it. 2. Using implicit and explicit intents to launch the second activity and pass data between activities. 3. Adding buttons, textviews and other controls in XML layout files and referencing them in Java code. 4. Setting onclick listeners on buttons to launch activities and display data with a toast message.

Uploaded by

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

Mad Lab Programs

The document describes developing an Android application using intents and controls. It includes: 1. Developing two activities - a main activity to enter data and a second activity to display it. 2. Using implicit and explicit intents to launch the second activity and pass data between activities. 3. Adding buttons, textviews and other controls in XML layout files and referencing them in Java code. 4. Setting onclick listeners on buttons to launch activities and display data with a toast message.

Uploaded by

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

1.

INTENT AND ACTIVITY

AIM:

To Develop an Android application by using intent and activity.

ALGORITHM:

STEP1:Start the program.

STEP 2:Set textview,editext and button in xml file.

STEP 3:Decalre and initailize the button and edittexts in main activity.

STEP 4:Set onclick listener for the button.

STEP 5:Create a new class.

STEP 6:Create a new xml file.

STEP 7:Set the path of webpage in the new xml file.

STEP 8:To click the button in the second screen.

STEP 9:The button helps to open a webpage.

STEP 10:Stop the program.


PROGRAM:

MainActivity.Java

package com.college.exercise1;

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

Thread timer;
timer=new Thread()
{
public void run()
{
try
{
sleep(10000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
finally {
MainActivity.this.finish();
Intent nn = new Intent(MainActivity.this,SecondScreen.class);
startActivity(nn);
}
}
};

timer.start();

}
}

SecondScreen.Java

package com.college.exercise1;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

public class SecondScreen extends AppCompatActivity {

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

public void ShowWebPage(View view)


{
Intent intent=new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.bing.com"));
startActivity(intent);
}

Activity_Main.XML

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


<androidx.constraintlayout.widget.ConstraintLayout
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"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView3"
android:layout_width="192dp"
android:layout_height="51dp"
android:text="Intent Testing"
android:textColor="@color/colorAccent"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.452"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.141" />

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="156dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="1. Implicit Intent"
android:textColor="@android:color/holo_green_dark"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.406"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView3" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:text="2. Explicit Intent"
android:textColor="@android:color/holo_green_dark"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.402"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:layout_constraintVertical_bias="0.158" />
</androidx.constraintlayout.widget.ConstraintLayout>

Activity_Second_screen.XML

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


<androidx.constraintlayout.widget.ConstraintLayout
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:visibility="visible"
tools:context=".SecondScreen"
android:background="@color/colorPrimary"
>

<TextView
android:id="@+id/textView4"
android:layout_width="217dp"
android:layout_height="40dp"
android:layout_marginStart="112dp"
android:layout_marginLeft="112dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:text="Second Screen"
android:textColor="@android:color/background_light"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.499"
tools:visibility="visible" />

<Button
android:id="@+id/button"
android:layout_width="221dp"
android:layout_height="64dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="116dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:onClick="ShowWebPage"
android:text="Click Me"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView4"
app:layout_constraintVertical_bias="0.0" />

</androidx.constraintlayout.widget.ConstraintLayout>
OUTPUT:
RESULT:
Thus the above android application was developed and verified successfully.

2.USING CONTROLS

AIM:

To Develop an android application by using buttons and controls.

ALGORITHM:

STEP 1:Start the program

STEP 2:Set textview,edittext and button in xml file

STEP 3:Decalre and initailize the button and edittexts in main activity

STEP 4:Set onclick listener for the button

STEP 5:TO fill the data in the first screen and transfer the data to second screen.

STEP 6:To show the data when we click the botton by using toast.

STEP 7:Stop the program.


PROGRAM:

MainActivity.Java

package com.college.exercise2;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;

public class MainActivity extends AppCompatActivity {

EditText txt1,txt2,txt3;
Spinner sp;
RadioGroup radioSexGroup;
RadioButton radioSexButton;
String degree[] = {"BSc","BCA","BA","BCom","MSc","MCA","MA","MCom"};
ArrayAdapter<String> adapter;

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

txt1 = (EditText)findViewById(R.id.nameTxt);
txt2 = (EditText)findViewById(R.id.fatherTxt);
txt3 = (EditText)findViewById(R.id.dobTxt);
radioSexGroup = (RadioGroup) findViewById(R.id.radioSex);
sp = (Spinner)findViewById(R.id.DegSpinner);
adapter = new
ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,degree);
sp.setAdapter(adapter);

public void SendData(View view)


{
String sname = txt1.getText().toString();
String fname = txt2.getText().toString();
String dob = txt3.getText().toString();
int selectedId = radioSexGroup.getCheckedRadioButtonId();
radioSexButton = (RadioButton) findViewById(selectedId);
String sex = radioSexButton.getText().toString();
String deg = sp.getSelectedItem().toString();

String data = sname + " , " + fname + " , " + dob + " , " + sex + " , " +
deg;
Intent tt = new Intent(MainActivity.this,DataScreen.class);
tt.putExtra("student_info",data);
startActivity(tt);

}
DataScreen.Java

package com.college.exercise2;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class DataScreen extends AppCompatActivity {

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

public void ShowValue(View view)


{
String passedArg = getIntent().getExtras().getString("student_info");
Toast.makeText(getApplicationContext(),passedArg, Toast.LENGTH_SHORT).show();
}
}

Activity_Data_Screen.XML

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


<androidx.constraintlayout.widget.ConstraintLayout
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"
tools:context=".DataScreen">

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="303dp"
android:onClick="ShowValue"
android:text="Show Data"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

Activity_Main.XML

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


<androidx.constraintlayout.widget.ConstraintLayout
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"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="48dp"
android:layout_marginLeft="48dp"
android:layout_marginTop="68dp"
android:text="Student Name"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/nameTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="53dp"
android:layout_marginEnd="17dp"
android:layout_marginRight="17dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="154dp"
android:text="Father Name:"
app:layout_constraintEnd_toEndOf="@+id/textView"
app:layout_constraintStart_toStartOf="@+id/textView3"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/fatherTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="17dp"
android:layout_marginRight="17dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBaseline_toBaselineOf="@+id/textView2"
app:layout_constraintEnd_toEndOf="parent" />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="53dp"
android:layout_marginLeft="53dp"
android:layout_marginBottom="6dp"
android:text="Date of Birth:"
app:layout_constraintBottom_toBottomOf="@+id/dobTxt"
app:layout_constraintStart_toStartOf="parent" />

<EditText
android:id="@+id/dobTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="38dp"
android:layout_marginEnd="17dp"
android:layout_marginRight="17dp"
android:ems="10"
android:inputType="date"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/fatherTxt" />

<TextView
android:id="@+id/textView4"
android:layout_width="63dp"
android:layout_height="34dp"
android:layout_marginStart="59dp"
android:layout_marginLeft="59dp"
android:layout_marginTop="58dp"
android:layout_marginEnd="59dp"
android:layout_marginRight="59dp"
android:text="Sex:"
app:layout_constraintEnd_toEndOf="@+id/textView2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView3" />

<RadioGroup
android:id="@+id/radioSex"
android:layout_width="207dp"
android:layout_height="126dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="51dp"
app:layout_constraintBottom_toBottomOf="@+id/textView5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/dobTxt"
app:layout_constraintVertical_bias="0.0">

<RadioButton
android:id="@+id/radioMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Male" />

<RadioButton
android:id="@+id/radioFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Female" />
</RadioGroup>

<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="53dp"
android:layout_marginLeft="53dp"
android:layout_marginEnd="47dp"
android:layout_marginRight="47dp"
android:text="Degree:"
app:layout_constraintEnd_toStartOf="@+id/DegSpinner"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/DegSpinner" />

<Spinner
android:id="@+id/DegSpinner"
android:layout_width="0dp"
android:layout_height="29dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="140dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView5" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="112dp"
android:layout_marginRight="112dp"
android:layout_marginBottom="56dp"
android:onClick="SendData"
android:text="Transfer Data"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

OUTPUT:
RESULT:

Thus the above android application was developed and verified successfully.

3.ALERT DIALOGS

AIM:

To develop an android application by using Alort Dialogs.

ALGORITHM:

STEP 1:Start the program.

STEP 2:Set an button in the xml file.


STEP 3:Declare and intialize the button.

STEP 4:Set on click listener for the button.

STEP 5:Make an alertdialog with three messages as yes,no and cancel,if the button was
clicked.

STEP 6:Show the clicked message using toast.

STEP 7: Close the program.

PROGRAM:

MainActivity.Java

package com.example.alertdialogtesting;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void ShowAlert(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Alert Dialog Example");
builder.setMessage("Are You sure, you want to continue ?");
builder.setCancelable(false);
builder.setPositiveButton("yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(MainActivity.this, "Selected Option: yes",
Toast.LENGTH_SHORT).show();
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(MainActivity.this, "Selected Option: No",
Toast.LENGTH_SHORT).show();
}
});
AlertDialog dialog = builder.create();
dialog.show();a
}
}

Activity_Main.XML

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


<androidx.constraintlayout.widget.ConstraintLayout
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:id="@+id/Button"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<Button
android:id="@+id/button"
android:layout_width="0dp"
android:layout_height="111dp"
android:layout_marginStart="1dp"
android:layout_marginLeft="1dp"
android:layout_marginEnd="1dp"
android:layout_marginRight="1dp"
android:onClick="ShowAlert"
android:text="ShowAlertDialog"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

OUTPUT:
RESULT:

Thus the above android application was developed and verified successfully.
4.LIST VIEW

AIM:

To develop an android application by using List View.

ALGORITHM:

STEP 1:Start the program.

STEP 2:Set listview in the xml file.

STEP 3:Declare and initialize the listview and adapter in main activity .

STEP 4:Set values into the adapter.

STEP 5:Set on click listener to the list view.

STEP 6:Show the clicked message using toast.

STEP 7:Stop the program.


PROGRAM:

MainActivity.Java

package com.example.list;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

ListView mylist;
ArrayAdapter<String> adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String androidversion[]={"Cupcake :1.5","Dount :1.6","Eclair :2.0","Froyo
:2.2","Gingerbread :2.3"};
mylist = (ListView)findViewById(R.id.outlist);
adapter=new
ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,androidversion);
mylist.setAdapter(adapter);
mylist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i,
long l) {
String value = adapter.getItem(i);

Toast.makeText(getApplicationContext(),value,Toast.LENGTH_SHORT).show();
}
});
}

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/outlist"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
OUTPUT:
RESULT:

Thus the above android application was developed and verified successfully.
5.OPTIONS MENU

AIM:

To develop an android application by using Options Menu.

ALGORITHM:

STEP 1:Start the program.

STEP 2:Set textview in the xml file.

STEP 3:Declare and initalize the textview in the main activity.

STEP 4:Create a new folder menu in res.

STEP 5:create an xml file in the menu folder.

STEP 6:create menu items in menu xml file.

STEP 7:Set on click listener to the textview.

STEP 8:Click the three dots it shows the declared options.

STEP 9:Close the program.


PROGRAM:

MainActivity.Java

package com.example.option;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.main,menu);
return true;
}
public boolean OnOptionItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.about:
Toast.makeText(this,"your are
selected"+item.getTitle().toString(),Toast.LENGTH_SHORT).show();
return true;

case R.id.help:
Toast.makeText(this,"your are
selected"+item.getTitle().toString(),Toast.LENGTH_SHORT).show();
return true;

case R.id.setting:
Toast.makeText(this,"your are
selected"+item.getTitle().toString(),Toast.LENGTH_SHORT).show();
return true;

case R.id.exit:
Toast.makeText(this,"your are
selected"+item.getTitle().toString(),Toast.LENGTH_SHORT).show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}

Main.XML

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


<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/about"
android:title="About"/>
<item android:id="@+id/help"
android:title="Help"/>
<item android:id="@+id/setting"
android:title="Setting"/>
<item android:id="@+id/exit"
android:title="Exit"/>
</menu>

Main_Activity.XML

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


<androidx.constraintlayout.widget.ConstraintLayout
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"
tools:context=".MainActivity"/>

OUTPUT:

x
RESULT:

Thus the above android application was developed and verified successfully.
6.SEEK BAR

AIM:

To develop an android application by using Seek Bar.

ALGORITHM:

STEP 1:Start the program.

STEP 2:Set text view,edit text and seek bar in the xml file.

STEP 3:Declare and initialize the text view and seek bar in the main activity.

STEP 4:To initialize the pval=0 for change the seek bar value.

STEP 5:To start the seek bar by using onStartTrackingTouch method.

STEP 6: To stop the seek bar by using onStopTrackingTouch method.

STEP 7:Close the program.


PROGRAM:

MainActivity.java

package com.example.seekbar;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.EditText;
import android.widget.SeekBar;

public class MainActivity extends AppCompatActivity{


SeekBar sBar;
EditText t1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sBar = (SeekBar)findViewById(R.id.seekBar);
t1 = (EditText)findViewById(R.id.txt1);

t1.setText(sBar.getProgress() + "/" + sBar.getMax());

sBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
int pval=0;
@Override

public void onProgressChanged(SeekBar seekBar, int i, boolean b) {


pval = i;
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
t1.setText(pval +"/" +sBar.getMax());
}
});
}
}

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

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="20dp"
android:text="seekBar Example"
android:textSize="30sp" />

<EditText
android:id="@+id/txt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:padding="20dp"
android:textSize="22dp"
android:layout_marginTop="20dp"
/>

<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:max="100"
android:padding="20dp"
android:progress="0" />
</LinearLayout>

OUTPUT:
RESULT:

Thus the above android application was developed and verified successfully.
7.SHARED PREFERENCES

AIM:
To develop an android application by using Shared Preferences .

ALGORITHM:

STEP 1:Start the program.

STEP 2:Set textviews,edittexts,buttons in the xml file.

STEP 3:Declare and initialize the edittexts,buttons,strings and shared preferences.

STEP 4:Set on on click listener for button1, button2 and button3.

STEP 5:Store the data from edittexts into the shared preferences,when the button1 is clicked.

STEP 6:Retrieve the data from shared preferences,when the button2 is clicked.

STEP 7:Show the data from the shared preferences,using the toast.

STEP 8:Exit from the second screen when the button3 is clicked.

STEP 9:Close the program.


PROGRAM:

MainActivity.Java
package com.example.sharedpreferenceexample;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

EditText t1,t2,t3,t4;
String Rollno = "rollkey";
String Sname = "namekey";
String Degree = "degreekey";
String Dept ="deptkey";
String Mypref = "Myprefs";
SharedPreferences sharedPreferences;

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

t1=(EditText)findViewById(R.id.rolltxt);
t2=(EditText)findViewById(R.id.nametxt);
t3=(EditText)findViewById(R.id.degreetxt);
t4=(EditText)findViewById(R.id.depttxt);
sharedPreferences = getSharedPreferences(Mypref, Context.MODE_PRIVATE);
}

public void SharedButton(View view) {

String rollno = t1.getText().toString();


String stuname = t2.getText().toString();
String degree = t3.getText().toString();
String dept = t4.getText().toString();
SharedPreferences.Editor editor = sharedPreferences.edit();

editor.putString(Rollno,rollno);
editor.putString(Sname,stuname);
editor.putString(Degree,degree);
editor.putString(Dept,dept);

editor.commit();

Toast.makeText(MainActivity.this,"SharedPreference values are


stored",Toast.LENGTH_SHORT).show();
Intent nxtScreen = new
Intent(getApplicationContext(),SharedValueShow.class);
startActivity(nxtScreen);

}
}
SharedValueShow.Java
package com.example.sharedpreferenceexample;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class SharedValueShow extends AppCompatActivity {

SharedPreferences sharedPreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shared_value_show);
sharedPreferences = getSharedPreferences("Myprefs", Context.MODE_PRIVATE);
}

public void ShowValue(View view) {

String rno = sharedPreferences.getString("rollkey","");


String sn = sharedPreferences.getString("namekey","");
String deg = sharedPreferences.getString("degreekey","");
String dpt = sharedPreferences.getString("deptkey","");
String allval = "Roll no: " + rno + "\nStudent Name: " + sn + "\nDegree: "
+ deg + "\nDepartment: " + dpt;

Toast.makeText(SharedValueShow.this,allval,Toast.LENGTH_SHORT).show();
}

public void ClearValue(View view) {


SharedPreferences.Editor editor = sharedPreferences.edit();
editor.clear();
editor.commit();
}

public void Exit(View view) {


finish();
}
}

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

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center_horizontal"
android:text="SharedPreferenceExample"
android:textSize="30dp" />

<EditText
android:id="@+id/rolltxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:ems="10"
android:gravity="center_horizontal|left"
android:hint="Roll No"
android:inputType="textPersonName"
android:padding="20dp"
android:textSize="20dp" />

<EditText
android:id="@+id/nametxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:ems="10"
android:gravity="center_horizontal|left"
android:hint="Student Name"
android:inputType="textPersonName"
android:padding="20dp"
android:textSize="20dp" />

<EditText
android:id="@+id/degreetxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:ems="10"
android:gravity="center_horizontal|left"
android:hint="Degree"
android:inputType="textPersonName"
android:padding="20dp"
android:textSize="20dp" />

<EditText
android:id="@+id/depttxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:ems="10"
android:gravity="center_horizontal|left"
android:hint="Department"
android:inputType="textPersonName"
android:padding="20dp"
android:textSize="20dp" />

<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="Save To Shared Preference"
android:textSize="15dp"
android:layout_marginTop="20dp"
android:onClick="SharedButton"
/>

</LinearLayout>

Activity_Shared_Value_Show.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:gravity="center_vertical"
android:orientation="vertical"
tools:context=".SharedValueShow">

<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Show Preference"
android:onClick="ShowValue"
/>

<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Clear Value"
android:onClick="ClearValue"
/>

<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Exit"
android:onClick="Exit"
/>
</LinearLayout>

OUTPUT:
RESULT:

Thus the above android application was developed and verified successfully.
8.STATUS BAR NOTIFICATIONS

AIM:
To develop an android application by using Status Bar Notifications.

ALGORITHM:

STEP 1:Start the program.

STEP 2:Set textviews,edittexts,imagebutton,buttons in the xml file.

STEP 3:Set application,activity and intent-filter in the manifest xml file.

STEP 4:Declare the button name b1.

STEP 5:To set smallicon,contenttitle,contenttext in the addnotification.

STEP 6:To create a new intent for MainActivity.class.

STEP 7:Show the notification example on your emulator.

STEP 8:Close the program.


PROGRAM:

MainActivity.Java

package com.example.notificationdemo;

import android.app.Activity;

import android.app.NotificationManager;

import android.app.PendingIntent;

import android.content.Context;

import android.content.Intent;

import android.support.v4.app.NotificationCompat;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

public class MainActivity extends Activity {

Button b1;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

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

b1.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

addNotification();

});
}

private void addNotification() {

NotificationCompat.Builder builder =

new NotificationCompat.Builder(this)

.setSmallIcon(R.drawable.abc)

.setContentTitle("Notifications Example")

.setContentText("This is a test notification");

Intent notificationIntent = new Intent(this, MainActivity.class);

PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,

PendingIntent.FLAG_UPDATE_CURRENT);

builder.setContentIntent(contentIntent);

// Add as notification

NotificationManager manager = (NotificationManager)


getSystemService(Context.NOTIFICATION_SERVICE);

manager.notify(0, builder.build());

ActivityMain.XML

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

<TextView

android:id="@+id/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Notification Example"

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:text="Tutorials point "

android:textColor="#ff87ff09"

android:textSize="30dp"

android:layout_below="@+id/textView1"

android:layout_centerHorizontal="true"

android:layout_marginTop="48dp" />

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

android:layout_marginTop="42dp" />

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Notification"

android:id="@+id/button"

android:layout_marginTop="62dp"

android:layout_below="@+id/imageButton"

android:layout_centerHorizontal="true" />

</RelativeLayout>

<RelativeLayout

Manifest.XML

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

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

package="com.example.notificationdemo" >

<application

android:allowBackup="true"

android:icon="@drawable/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme" >
<activity

android:name="com.example.notificationdemo.MainActivity"

android:label="@string/app_name" >

<intent-filter>

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

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

</intent-filter>

</activity>

<activity android:name=".NotificationView"

android:label="Details of notification"

android:parentActivityName=".MainActivity">

<meta-data

android:name="android.support.PARENT_ACTIVITY"

android:value=".MainActivity"/>

</activity>

</application>

</manifest>
OUTPUT:
RESULT:

Thus the above android application was developed and verified successfully.
9.TAB WIDGETS TALKING CLOCK

AIM:

To Develop an android application by using tab widgets talking clock.

ALGORITHM:

STEP 1:Start the program

STEP 2:To set the buttons and textview in xml file

STEP 3:Decalre and initialize the button and textview in main activity

STEP 4:To use for loop to initialize app widgets length

STEP 5:Make a toast as widget added

STEP 6:Click the widget button to show the specific application

STEP 7:Stop the program.


PROGRAM:

MainActivity.Java

package com.example.sairamkrishna.myapplication;

import android.app.PendingIntent;

import android.appwidget.AppWidgetManager;

import android.appwidget.AppWidgetProvider;

import android.content.Context;

import android.content.Intent;

import android.net.Uri;

import android.widget.RemoteViews;

import android.widget.Toast;

public class MainActivity extends AppWidgetProvider{

public void onUpdate(Context context, AppWidgetManager appWidgetManager,int[]


appWidgetIds) {

for(int i=0; i<appWidgetIds.length; i++){

int currentWidgetId = appWidgetIds[i];

String url = "http://www.tutorialspoint.com";

Intent intent = new Intent(Intent.ACTION_VIEW);

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

intent.setData(Uri.parse(url));

PendingIntent pending = PendingIntent.getActivity(context, 0,intent, 0);

RemoteViews views = new RemoteViews(context.getPackageName(),R.layout.activity_main);

views.setOnClickPendingIntent(R.id.button, pending);

appWidgetManager.updateAppWidget(currentWidgetId,views);

Toast.makeText(context, "widget added", Toast.LENGTH_SHORT).show();

}
}

ActivityMain.XML

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

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

xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"

android:layout_height="match_parent"
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">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Tutorials point"

android:id="@+id/textView"

android:layout_centerHorizontal="true"

android:textColor="#ff3412ff"

android:textSize="35dp" />

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Widget"

android:id="@+id/button"
android:layout_centerHorizontal="true"

android:layout_marginTop="61dp"

android:layout_below="@+id/textView" />

</RelativeLayout>

Manifest.XML

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

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

<receiver android:name=".MainActivity">

<intent-filter>

<action android:name="android.appwidget.action.APPWIDGET_UPDATE"></action>

</intent-filter>

<meta-data android:name="android.appwidget.provider"

android:resource="@xml/mywidget"></meta-data>

</receiver>

</application>

</manifest>
OUTPUT:
RESULT:

Thus the above android application was developed and verified successfully.
10.TWEEN ANIMATION

AIM:

To Develop an android application by using tween animation.

ALGORITHM:

STEP 1:Start the program

STEP 2:To set buttons fade,move,rotate and zoom in xml file

STEP 3:Decalre and initailize the button and image view in main activity

STEP 4: Show the clicked message using toast

STEP 5: The animation was running when the button was clicked

STEP 6: Stop the program.


PROGRAM:
src/com.tween.pack/TweenActivity.java

package com.tween.pack;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.Toast;

public class TweenActivity extends Activity {

ImageView image;

public void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);
setContentView(R.layout.main);
image=(ImageView)findViewById(R.id.imageView1);

}
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.menu_file,menu);
return true;

}
public boolean onOptionsItemSelected(MenuItem item)
{
Animation animation;

Toast.makeText(getApplicationContext(),"Clicked:"+item,Toast.LENGTH_LONG).show();
switch(item.getItemId())
{
case R.id.rotate:
animation= AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.rotate);
image.startAnimation(animation);
return true;

case R.id.fade:
animation= AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.fade);
image.startAnimation(animation);
return true;
case R.id.zoom:
animation= AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.zoom);
image.startAnimation(animation);
return true;

case R.id.move:
animation= AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.move);
image.startAnimation(animation);
return true;

}
return false;
}

res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical" >

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />

</LinearLayout>

res/menu/menu_file.xml

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


<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/fade"
android:title="FADE">
</item>
<item
android:id="@+id/move"
android:title="MOVE">
</item>
<item
android:id="@+id/rotate"
android:title="ROTATE">
</item>
<item
android:id="@+id/zoom"
android:title="ZOOM">
</item>

</menu>

res/anim/fade.xml

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

<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="3000"/>

</set>

res/anim/move.xml

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

<translate
android:fromXDelta="-75%p"
android:toXDelta="75%p"
android:duration="2000" />
</set>

res/anim/rotate.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000">

</rotate>
<rotate
android:startOffset="1500"
android:fromDegrees="360"
android:toDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000">

</rotate>

</set>

res/anim/zoom.xml

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

<scale
android:fromXScale="0.5"
android:toXScale="2.5"
android:fromYScale="0.5"
android:toYScale="2.5"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000" >
</scale>

</set>

OUTPUT:
RESULT:

Thus the above android application was developed and verified successfully.
11.GRID VIEW

AIM:

To Develop an android application by using grid view.

ALGORITHM:

STEP 1:Start the program

STEP 2:Set gridview into the xml file

STEP 3:Declare and initialize the gridview and adapter in the main activity

STEP 4:Set adapter into the gridview

STEP 5:Set on item click listener to the adapter

STEP 6:Show the clicked item in the gridview using toast

STEP 7:Stop the program.


PROGRAM:

src/com.gridview.pack.GridViewActivity.java

package com.gridview.pack;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.Toast;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;

public class GridViewActivity extends Activity


{

GridView gv;
static final String[] number = new
String[]{"Mango","Apple","Pine","Lemon","Graphes","Coconut","Banana","Orange"};
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

gv=(GridView)findViewById(R.id.gridView1);
ArrayAdapter<String> adapter = new
ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,number);
gv.setAdapter(adapter);

gv.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent ,View view,int position,long id)
{
Toast.makeText(getApplication(),((TextView)view).getText(),Toast.LENGTH_SHORT)
.show();
}

});

}
}
res/layout/main.xml

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

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

<GridView
android:id="@+id/gridView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="3" >
</GridView>

</LinearLayout>
OUTPUT:
RESULT:

Thus the above android application was developed and verified successfully.
12.INTERNAL STORAGE FILES

AIM:

To Develop an android application by using internal storage files.

ALGORITHM:

STEP 1:Start the program

STEP 2:To set button save and load in the xml file

STEP 3:To set textview,imageview and edittext in xml file

STEP 4: To click the button save it shows file saved

STEP 5: To initialize the button ,textview and edittext in mainactivity

STEP 6:Show the clicked message using toast

STEP7:To used for inputstream and outputstream in internal storage files in mainactivity

STEP 7: Close the program.


PROGRAM:

MainActivity.Java

package com.example.sairamkrishna.myapplication;

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TextView;

import android.widget.Toast;

import java.io.FileInputStream;

import java.io.FileOutputStream;

public class MainActivity extends Activity {

Button b1,b2;

TextView tv;

EditText ed1;

String data;

private String file = "mydata";

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

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

b2=(Button)findViewById(R.id.button2);

ed1=(EditText)findViewById(R.id.editText);
tv=(TextView)findViewById(R.id.textView2);

b1.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

data=ed1.getText().toString();

try {

FileOutputStream fOut = openFileOutput(file,MODE_WORLD_READABLE);

fOut.write(data.getBytes());

fOut.close();

Toast.makeText(getBaseContext(),"file saved",Toast.LENGTH_SHORT).show();

catch (Exception e) {

e.printStackTrace();

});

b2.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

try {

FileInputStream fin = openFileInput(file);

int c;

String temp="";

while( (c = fin.read()) != -1){

temp = temp + Character.toString((char)c);

tv.setText(temp);
Toast.makeText(getBaseContext(),"file read",Toast.LENGTH_SHORT).show();

catch(Exception e){

});

ActivityMain.XML

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

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

xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"

android:layout_height="match_parent"
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">

<TextView android:text="Internal storage" android:layout_width="wrap_content"

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

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Save"

android:id="@+id/button"

android:layout_alignParentBottom="true"

android:layout_alignLeft="@+id/textView"

android:layout_alignStart="@+id/textView" />

<EditText

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/editText"

android:hint="Enter Text"

android:focusable="true"

android:textColorHighlight="#ff7eff15"

android:textColorHint="#ffff25e6"

android:layout_below="@+id/imageView"

android:layout_alignRight="@+id/textView"

android:layout_alignEnd="@+id/textView"
android:layout_marginTop="42dp"

android:layout_alignLeft="@+id/imageView"

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

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

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="load"

android:id="@+id/button2"

android:layout_alignTop="@+id/button"

android:layout_alignRight="@+id/editText"

android:layout_alignEnd="@+id/editText" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Read"

android:id="@+id/textView2"

android:layout_below="@+id/editText"
android:layout_toLeftOf="@+id/button2"

android:layout_toStartOf="@+id/button2"

android:textColor="#ff5bff1f"

android:textSize="25dp" />

</RelativeLayout>

Manifest.XML

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

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

<activity

android:name=".MainActivity"

android:label="@string/app_name" >

<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 application was developed and verified successfully.
13.SQLITE-DATABASE

AIM:

To Develop an android application by using SQlite-Database

ALGORITHM:

STEP 1:Start the program

STEP 2:To set text view and edit text in the xml file

STEP 3:To set buttons add,delete,search and clear in xml file

STEP 4:To create SQlite-database in mainactivity file

STEP 5:To click the button add it shows value inserted

STEP6:To click the button delete it shows record deleted

STEP7:To click the button search the SQlite -database

STEP 8:Stop the program.


PROGRAM:
Src/com.sqlpack/SQLActivity.java

package com.sql.pack;
import android.app.Activity;
import android.os.Bundle;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class SQLActivity extends Activity {

EditText txtRegNo,txtName, txtDept;


Button btnAdd,btnDelete,btnSearch,btnClear;
String stName,stRegNO,searchStudent,stDept;
SQLiteDatabase sqlDb;

public void onCreate(Bundle savedInstanceState) {


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

sqlDb=openOrCreateDatabase("STDB",getApplicationContext().MODE_PRIVATE,null);
sqlDb.execSQL("CREATE TABLE IF NOT EXISTS STDINFORMATION(REGNO
VARCHAR(12),NAME VARCHAR(20),DEPT VARCHAR(20))");

txtRegNo= (EditText) findViewById(R.id.editText2);


txtName= (EditText) findViewById(R.id.editText1);
txtDept= (EditText) findViewById(R.id.editText3);

btnAdd= (Button) findViewById(R.id.button1);


btnDelete= (Button) findViewById(R.id.button2);
btnSearch= (Button) findViewById(R.id.button3);
btnClear= (Button) findViewById(R.id.button4);

btnAdd.setOnClickListener(new View.OnClickListener()
{

public void onClick(View arg0)


{
stRegNO = txtRegNo.getText().toString().trim();
stName = txtName.getText().toString().trim();
stDept = txtDept.getText().toString().trim();

if(stRegNO.equals("")||stName.equals("")||stDept.equals(""))
{
Toast.makeText(getApplicationContext(), "Fields cannot be
empty",Toast.LENGTH_SHORT).show();

}
else
{
sqlDb.execSQL("INSERT INTO STDINFORMATION(REGNO,NAME,DEPT)
VALUES('"+stRegNO+"','"+stName+"','"+stDept+"')");

Toast.makeText(getApplicationContext(),"Value Inserted!!",Toast.LENGTH_SHORT)
.show();
txtRegNo.setText("");
txtName.setText("");
txtDept.setText("");
}

});

btnDelete.setOnClickListener(new View.OnClickListener()
{

public void onClick(View arg0)


{

searchStudent = txtRegNo.getText().toString().trim();
if(searchStudent.equals(""))

{
Toast.makeText(getApplicationContext(), "Fields cannot be
empty!!",Toast.LENGTH_SHORT).show();
return;
}

Cursor cDel = sqlDb.rawQuery("SELECT * FROM STDINFORMATION WHERE REGNO


= '"+searchStudent+"'",null);

if(cDel.moveToFirst())

sqlDb.execSQL("DELETE FROM STDINFORMATION WHERE REGNO


= '"+searchStudent+"'");
Toast.makeText(getApplicationContext(), "RECORDDELETED",Toast.LENGTH_SHORT)
.show();
txtRegNo.setText("");
txtName.setText("");
txtDept.setText("");
}

Else
{
Toast.makeText(getApplicationContext(), "Data not found!!",Toast.LENGTH_SHORT)
.show();
}

}
});

btnSearch.setOnClickListener(new View.OnClickListener()
{

public void onClick(View arg0)


{
searchStudent = txtRegNo.getText().toString().trim();

if(searchStudent.equals(""))
{
Toast.makeText(getApplicationContext(), "Fields cannot be
empty!!",Toast.LENGTH_SHORT).show();
return;
}

Cursor c = sqlDb.rawQuery("SELECT * FROM STDINFORMATION WHERE REGNO =


'"+searchStudent+"'",null);

if(c.moveToFirst())
{
txtRegNo.setText(c.getString(0));
txtName.setText(c.getString(1));
txtDept.setText(c.getString(2));
}

else
{
Toast.makeText(getApplicationContext(), "Data not
found!!",Toast.LENGTH_SHORT).show();
}

}
});

btnClear.setOnClickListener(new View.OnClickListener()
{

public void onClick(View arg0)


{

txtRegNo.setText("");
txtName.setText("");
txtDept.setText("");

}
});

}
}

res/layout/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" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="72dp"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="42dp"
android:text="RegNo"
android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView2"
android:layout_marginTop="44dp"
android:text="Dept"
android:textAppearance="?android:attr/textAppearanceLarge" />

<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button2"
android:layout_alignTop="@+id/textView3"
android:ems="10" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignRight="@+id/textView2"
android:layout_below="@+id/editText3"
android:layout_marginTop="53dp"
android:text="ADD" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button1"
android:layout_alignBottom="@+id/button1"
android:layout_marginLeft="18dp"
android:layout_toRightOf="@+id/textView2"
android:text="DELETE" />

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/button2"
android:layout_marginLeft="16dp"
android:layout_toRightOf="@+id/button2"
android:text="SEARCH" />

<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/button3"
android:layout_alignParentRight="true"
android:text="CLEAR" />

<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView2"
android:layout_alignBottom="@+id/textView2"
android:layout_alignLeft="@+id/editText3"
android:ems="10" />

<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView1"
android:layout_alignBottom="@+id/textView1"
android:layout_alignLeft="@+id/editText2"
android:ems="10" />

</RelativeLayout>
</LinearLayout>

OUTPUT:
RESULT:

Thus the above android application was developed and verified successfully.
14.GOOGLE MAP

AIM:

To Develop an android application by using Google map

ALGORITHM:

STEP 1:Start the program

STEP 2:To set fine location in the xml file

STEP 3:To set coarse location in xml file

STEP 4:To set internet connection access in xml file

STEP5:To obtain the support map fragment

STEP 6:To get notified when the map is read to be used

STEP 7:Add a marker in the location and move the camera

STEP 8: Close the program.


PROGRAM:

MainActivity.Java

package example.com.mapexample;

import android.support.v4.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;

public class MapsActivity extends FragmentActivity implements


OnMapReadyCallback{

private GoogleMap mMap;

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

SupportMapFragment mapFragment = (SupportMapFragment)


getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);

@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;

LatLng sydney = new LatLng(-34, 151);


mMap.addMarker(new MarkerOptions().position(sydney).title("Marker
in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));

}
}

ActivtyMain.XML

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

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

package="example.com.mapexample">

<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use

Google Maps Android API v2, but you must specify either coarse or fine

location permissions for the 'MyLocation' functionality.

-->

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<uses-permission android:name="android.permission.INTERNET" />

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

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

OUTPUT:
RESULT:

Thus the above android application was developed and verified successfully.
15.PERMISSIONS

AIM:

To Develop an android application by using Permissions

ALGORITHM:

STEP 1:Start the program

STEP 2:Set button in the xml file

STEP 3:Declare and initalize the button in the main activity

STEP 4:To Click the button then the button helps to open a warning message

STEP 5:If you click the Allow button then permission is granted

STEP 6: To click the button again it shows permission is already granted

STEP 7: Close the program.

.
PROGRAM:

MainActivity.Java

package org.geeksforgeeks.requestPermission;

import android.Manifest;

import android.content.pm.PackageManager;

import android.support.annotation.NonNull;

import android.support.v4.app.ActivityCompat;

import android.support.v4.content.ContextCompat;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

private Button storage, camera;

private static final int CAMERA_PERMISSION_CODE = 100;

private static final int STORAGE_PERMISSION_CODE = 101;

@Override

protected void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

storage = findViewById(R.id.storage);

camera = findViewById(R.id.camera);

storage.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v)


{

checkPermission(

Manifest.permission.WRITE_EXTERNAL_STORAGE,

STORAGE_PERMISSION_CODE);

});

camera.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v)

checkPermission(Manifest.permission.CAMERA,

CAMERA_PERMISSION_CODE);

});

public void checkPermission(String permission, int requestCode)

if (ContextCompat.checkSelfPermission(MainActivity.this, permission)

== PackageManager.PERMISSION_DENIED) {

ActivityCompat.requestPermissions(MainActivity.this,

new String[] { permission },

requestCode);

else {

Toast.makeText(MainActivity.this,

"Permission already granted",


Toast.LENGTH_SHORT)

.show();

@Override

public void onRequestPermissionsResult(int requestCode,

@NonNull String[] permissions,

@NonNull int[] grantResults)

super

.onRequestPermissionsResult(requestCode,

permissions,

grantResults);

if (requestCode == CAMERA_PERMISSION_CODE) {

if (grantResults.length > 0

&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {

Toast.makeText(MainActivity.this,

"Camera Permission Granted",

Toast.LENGTH_SHORT)

.show();

else {

Toast.makeText(MainActivity.this,

"Camera Permission Denied",

Toast.LENGTH_SHORT)

.show();

}
}

else if (requestCode == STORAGE_PERMISSION_CODE) {

if (grantResults.length > 0

&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {

Toast.makeText(MainActivity.this,

"Storage Permission Granted",

Toast.LENGTH_SHORT)

.show();

else {

Toast.makeText(MainActivity.this,

"Storage Permission Denied",

Toast.LENGTH_SHORT)

.show();

MainActivity.XML

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

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

tools:context=".MainActivity">
<!-- To show toolbar-->

<android.support.v7.widget.Toolbar

android:id="@+id/toolbar"

android:layout_width="match_parent"

android:background="@color/colorPrimary"

app:title="GFG | Permission Example"

app:titleTextColor="@android:color/white"

android:layout_height="?android:attr/actionBarSize"/>

<!--Button to request storage permission-->

<Button

android:id="@+id/storage"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Storage"

android:layout_marginTop="16dp"

android:padding="8dp"

android:layout_below="@id/toolbar"

android:layout_centerHorizontal="true"/>

<!--Button to request camera permission-->

<Button

android:id="@+id/camera"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Camera"
android:layout_marginTop="16dp"

android:padding="8dp"

android:layout_below="@id/storage"

android:layout_centerHorizontal="true"/>

</RelativeLayout>

Manifest.XML

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

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

package="org.geeksforgeeks.requestPermission">

<!--Declaring the required permissions-->

<uses-permission

android:name="android.permission.READ_EXTERNAL_STORAGE" />

<uses-permission

android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<uses-permission

android:name="android.permission.CAMERA" />

<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 application was developed and verified successfully.

You might also like