Mad Record
Mad Record
Mad Record
1 SIMPLE ANDROID
APPLICATION.
2
WORKING WITH ACTIVITY
3 WORKING WITH
FRAGMENTS
8
EMAILING
9
TELEPHONY
SMS
10
SIMPLE ANDROID APPLICATION
Activity_main.xml [code]
MainActivity.java
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.Switch;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RelativeLayout relativeLayout;
relativeLayout = findViewById(R.id.RelativeLayout);
Switch sw1=findViewById(R.id.switch1);
sw1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(sw1.isChecked()){
relativeLayout.setBackgroundColor(Color.DKGRAY);
}
else{
relativeLayout.setBackgroundColor(Color.WHITE);
}
});
}
Output
WORKING WITH ACTIVITY
Activity_Main.xml
</RelativeLayout>
MainActivity.java
package com.example.wwalab2;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.RelativeLayout;
import android.content.Intent;
public class MainActivity extends AppCompatActivity {
Button btnMad,btnSpm;
RelativeLayout rLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rLayout = (RelativeLayout) findViewById(R.id.r_layout);
btnMad = (Button) findViewById(R.id.btnMad);
btnSpm = (Button) findViewById(R.id.btnSpm);
btnMad.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent indent1=new Intent(getApplicationContext(),Activity2Mad.class);
startActivity(indent1);
}});
btnSpm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent indent2=new Intent(getApplicationContext(),Activity3SPM.class);
startActivity(indent2);
}});
}
}
activity_activity2Mad.xml
<TextView
android:id="@+id/textView2"
android:layout_width="300dp"
android:layout_height="126dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="53dp"
android:layout_marginTop="237dp"
android:layout_marginEnd="57dp"
android:layout_marginBottom="368dp"
android:text="Mobile application development is the process of creating software
applications that run on a mobile device."
android:textAlignment="viewStart"
android:textColor="#009688"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView3"
android:layout_width="251dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="77dp"
android:layout_marginEnd="83dp"
android:layout_marginBottom="562dp"
android:text="MOBILE APPLICATION DEVELOPMENT"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="#673AB7"
android:textSize="24sp"
android:textStyle="bold" />
</RelativeLayout>
Activity2Mad.java
package com.example.wwalab2;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.RelativeLayout;
import android.content.Intent;
public class Activity2Mad extends AppCompatActivity {
Button btnHome;
RelativeLayout rlayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity2_mad);
rlayout = (RelativeLayout) findViewById(R.id.r_Layout);
btnHome = (Button) findViewById(R.id.btnHome);
btnHome.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent indent=new Intent(getApplicationContext(), MainActivity.class);
startActivity(indent);
}
});
}
}
activity_activity3Spm.xml
<TextView
android:id="@+id/textView5"
android:layout_width="334dp"
android:layout_height="122dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="39dp"
android:layout_marginBottom="421dp"
android:text="Software Project Management (SPM) is a proper way of planning and
leading software projects."
android:textAlignment="textStart"
android:textColor="#673AB7"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:id="@+id/btnHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="156dp"
android:layout_marginBottom="315dp"
android:text="Go Home" />
</RelativeLayout>
Activity_activity3_spm.xml
package com.example.wwalab2;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.RelativeLayout;
import android.content.Intent;
public class Activity3SPM extends AppCompatActivity {
Button btnHome;
RelativeLayout rlayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity3_spm);
rlayout = (RelativeLayout) findViewById(R.id.r_layout);
btnHome=(Button) findViewById(R.id.btnHome);
btnHome.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent indent=new Intent(getApplicationContext(), MainActivity.class);
startActivity(indent);
}
});
}
}
WORKING WITH FRAGMENTS
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context=".MainActivity">
<fragment
android:layout_height="match_parent"
android:layout_width="350px"
class="com.example.fragdemo.ListMenuFragment"
android:id="@+id/fragment"/>
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.example.fragdemo.DetailsFragment"
android:id="@+id/fragment2"/>
</LinearLayout>
Listitems_info.xml
Details_info.xml
DetailsFraments.java
package com.example.fragdemo;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
ListMenuFragment.java
package com.example.fragdemo;
import android.app.ListFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
MainActivity.java
package com.example.fragdemo;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
UI CONTROLS (TEXT, EDIT TEXT, BUTTON, RADIO BUTTON)
Activity_main.xml
package com.example.radiobutton;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
RadioButton red,blue,green;
Button btnsubmit;
TextView txtView;
LinearLayout lnrlayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
red=(RadioButton )findViewById(R.id.red);
blue=(RadioButton )findViewById(R.id.blue);
green = (RadioButton)findViewById(R.id.green);
btnsubmit=(Button)findViewById(R.id.btnSumbit);
txtView = (TextView)findViewById(R.id.txtDisplay);
lnrlayout = (LinearLayout)findViewById(R.id.lnrlayout);
btnsubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(red.isChecked())
{
txtView.setText("You've Selected RED");
lnrlayout.setBackgroundColor(Color.RED);
}
if(blue.isChecked())
{
txtView.setText("You've seleceted BLUE");
lnrlayout.setBackgroundColor(Color.BLUE);
}
if(green.isChecked())
{
txtView.setText("You've Selected Green");
lnrlayout.setBackgroundColor(Color.GREEN);
}
}
});
}
}
UI Controls (Check Box, and Layout, Image Button, Toggle Button)
Activity_main.xml
package com.example.uicontrolsii;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;
import android.widget.ToggleButton;
import android.os.Bundle;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.RelativeLayout;
public class MainActivity extends AppCompatActivity {
CheckBox mad,spm,hr;
TextView txtshow;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ToggleButton tb1 = (ToggleButton)findViewById(R.id.toggle1);
final RelativeLayout relativeLayout;
relativeLayout = findViewById(R.id.r_layout);
txtshow = (TextView)findViewById(R.id.TxtShow);
mad=(CheckBox)findViewById(R.id.chkmad);
spm=(CheckBox)findViewById(R.id.chkspm);
hr=(CheckBox)findViewById(R.id.chkhr);
ImageButton btnshare = (ImageButton)findViewById(R.id.ShareBtn);
tb1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked) {
relativeLayout.setBackgroundResource(R.color.black);
}
else {
relativeLayout.setBackgroundResource(R.color.white);
}
}
});
btnshare.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String result = "Selected Courses";
if(mad.isChecked() ){
result += "\nMAD";
}
if(spm.isChecked() ){
result += "\nSPM";
}
if(hr.isChecked() ){
result += "\nHR";
}
txtshow.setText(":" + result);
}
});
}
}
UI CONTROLS (RATING BAR, LIST VIEW, GALLERY)
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context=".MainActivity">
<fragment
android:layout_height="match_parent"
android:layout_width="350px"
class="com.example.fragdemo.ListMenuFragment"
android:id="@+id/fragment"/>
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.example.fragdemo.DetailsFragment"
android:id="@+id/fragment2"/>
</LinearLayout>
Listitems_info.xml
Details_info.xml
<RatingBar
android:id="@+id/ratingBar1"
android:layout_width="291dp"
android:layout_height="75dp"
android:layout_marginLeft="80dp"
android:layout_marginTop="200dp"
android:numStars="5"
android:rating="3.5" />
<Button
android:id="@+id/btnGet"
android:layout_width="104dp"
android:layout_height="wrap_content"
android:layout_below="@+id/ratingBar1"
android:layout_alignLeft="@+id/ratingBar1"
android:layout_marginLeft="60dp"
android:layout_marginTop="30dp"
android:text="Get Rating" />
<TextView
android:id="@+id/textview1"
android:layout_width="223dp"
android:layout_height="69dp"
android:layout_below="@+id/btnGet"
android:layout_alignLeft="@+id/btnGet"
android:layout_marginTop="20dp"
android:textSize="20dp"
android:textStyle="bold" />
</LinearLayout>
DetailsFraments.java
package com.example.fragdemo;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Button;
import android.widget.RatingBar;
public class DetailsFragment extends Fragment {
TextView name,location;
private RatingBar rBar;
private TextView tView;
private Button btn;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState) {
View view = inflater.inflate(R.layout.details_info, container, false);
name = (TextView)view.findViewById(R.id.Name);
location = (TextView)view.findViewById(R.id.Location);
rBar = (RatingBar)view.findViewById(R.id.ratingBar1);
tView = (TextView)view.findViewById(R.id.textview1);
btn = (Button)view.findViewById(R.id.btnGet);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int noofstars = rBar.getNumStars();
float getrating = rBar.getRating();
tView.setText("Rating: "+getrating+"/"+noofstars);
}
});
return view;
}
public void change(String uname, String ulocation){
name.setText(uname);
location.setText(ulocation);
}
}
ListMenuFragment.java
package com.example.fragdemo;
import android.app.ListFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class ListMenuFragment extends ListFragment {
String[] users = new String[] { "Devi","Ishwarya","Pavithra","Radha" };
String[] location = new String[]{"Thatchur","Kallakurichi","Thatchur","Eamaper"};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState) {
View view =inflater.inflate(R.layout.listitems_info, container, false);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1, users);
setListAdapter(adapter);
return view;
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
DetailsFragment txt =
(DetailsFragment)getFragmentManager().findFragmentById(R.id.fragment2);
txt.change("Name: "+ users[position],"Location : "+ location[position]);
getListView().setSelector(android.R.color.holo_blue_dark);
}
}
MainActivity.java
package com.example.fragdemo;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Output
CRUD OPERATIONS USING SQLITE DB
Activity_main.xml
Listviewdatalayout.xml
MainActivity.java
package com.example.sqllite;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText GetName,GetPhoneNumber,GetSubject ;
Button Submit, EditData, DisplayData;
SQLiteDatabase SQLITEDATABASE;
String Name, PhoneNumber, Subject ;
Boolean CheckEditTextEmpty ;
String SQLiteQuery ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GetName = (EditText)findViewById(R.id.editText1);
GetPhoneNumber = (EditText)findViewById(R.id.editText2);
GetSubject = (EditText)findViewById(R.id.editText3);
Submit = (Button)findViewById(R.id.button1);
EditData = (Button)findViewById(R.id.button2);
DisplayData = (Button)findViewById(R.id.button3);
Submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DBCreate();
SubmitData2SQLiteDB();
} });
EditData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, EditDataActivity.class);
startActivity(intent);
} });
DisplayData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, ListViewActivity.class);
startActivity(intent);
} }); }
public void DBCreate(){
SQLITEDATABASE = openOrCreateDatabase("DemoDataBase", Context.MODE_PRIVATE,
null);
SQLITEDATABASE.execSQL("CREATE TABLE IF NOT EXISTS demoTable(id INTEGER
PRIMARY KEY AUTOINCREMENT NOT NULL, name VARCHAR, phone_number
VARCHAR, subject VARCHAR);");
}
public void SubmitData2SQLiteDB(){
Name = GetName.getText().toString();
PhoneNumber = GetPhoneNumber.getText().toString();
Subject = GetSubject.getText().toString();
CheckEditTextIsEmptyOrNot( Name,PhoneNumber, Subject);
if(CheckEditTextEmpty == true)
{
SQLiteQuery = "INSERT INTO demoTable (name,phone_number,subject)
VALUES('"+Name+"', '"+PhoneNumber+"', '"+Subject+"');";
SQLITEDATABASE.execSQL(SQLiteQuery);
EditDataActivity.java
package com.example.sqllite;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class EditDataActivity extends AppCompatActivity {
Button nextbutton, previousbutton, updatebutton, deletebutton;
EditText name, phoneNumber, SubJect;
SQLiteDatabase SQLITEDATABASE, SQLITEDATABASE2 ;
String GetSQliteQuery, UpdateRecordQuery, DeleteQuery ;
Cursor cursor, cursorCheckDataIsEmptyOrNot ;
TextView idtextview;
Boolean CheckEditTextEmpty;
String GetName,GetPhoneNumber,GetSubject ;
int UserID ;
String ConvertUserID ;
SQLiteHelper SQLITEHELPER;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_data);
nextbutton = (Button)findViewById(R.id.button1);
previousbutton = (Button)findViewById(R.id.button2);
updatebutton = (Button)findViewById(R.id.button3);
deletebutton = (Button)findViewById(R.id.button4);
name = (EditText)findViewById(R.id.editText1);
phoneNumber = (EditText)findViewById(R.id.editText2);
SubJect = (EditText)findViewById(R.id.editText3);
idtextview = (TextView)findViewById(R.id.textview1);
GetSQliteQuery = "SELECT * FROM demoTable" ;
SQLITEDATABASE = openOrCreateDatabase("DemoDataBase",
Context.MODE_PRIVATE, null);
cursor = SQLITEDATABASE.rawQuery(GetSQliteQuery, null);
cursor.moveToFirst();
GetSQLiteDatabaseRecords();
nextbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!cursor.isLast()){
cursor.moveToNext();
}
GetSQLiteDatabaseRecords();
} });
previousbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!cursor.isFirst()){
cursor.moveToPrevious();
}
GetSQLiteDatabaseRecords();
}
});
updatebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
GetName = name.getText().toString();
GetPhoneNumber = phoneNumber.getText().toString();
GetSubject = SubJect.getText().toString();
ConvertUserID = idtextview.getText().toString();
UserID = Integer.parseInt(ConvertUserID);
UpdateRecordQuery = "UPDATE demoTable SET name='" + GetName + "', phone_number='"
+ GetPhoneNumber + "', subject='" + GetSubject + "' WHERE id=" + UserID + ";";
CheckEditTextIsEmptyOrNot( GetName,GetPhoneNumber, GetSubject);
if (CheckEditTextEmpty == false) {
SQLITEDATABASE.execSQL(UpdateRecordQuery);
cursor = SQLITEDATABASE.rawQuery(GetSQliteQuery, null);
cursor.moveToPosition(UserID);
Toast.makeText(EditDataActivity.this,"Data Updated Successfully", Toast.LENGTH_LONG).show();
}else {
Toast.makeText(EditDataActivity.this,"Please Fill All the Fields", Toast.LENGTH_LONG).show();
} } });
deletebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ConvertUserID = idtextview.getText().toString();
UserID = Integer.parseInt(ConvertUserID);
DeleteQuery = "DELETE FROM demoTable WHERE id=" + UserID + ";";
SQLITEDATABASE.execSQL(DeleteQuery);
Toast.makeText(EditDataActivity.this, "Record Deleted Successfully", Toast.LENGTH_LONG).show();
cursor = SQLITEDATABASE.rawQuery(GetSQliteQuery, null);
}
});
}
public void GetSQLiteDatabaseRecords(){
idtextview.setText(cursor.getString(0));
name.setText(cursor.getString(1).toString());
phoneNumber.setText(cursor.getString(2).toString());
SubJect.setText(cursor.getString(3).toString());
}
public void CheckEditTextIsEmptyOrNot(String Name,String PhoneNumber, String subject
){
if(TextUtils.isEmpty(Name) || TextUtils.isEmpty(PhoneNumber) ||
TextUtils.isEmpty(subject)){
CheckEditTextEmpty = true ;
}
else {
CheckEditTextEmpty = false ;
}
}
ListViewActivity.java
package com.example.sqllite;
import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.ListView;
public class ListViewActivity extends AppCompatActivity {
SQLiteHelper SQLITEHELPER;
SQLiteDatabase SQLITEDATABASE;
Cursor cursor;
SQLiteListAdapter ListAdapter ;
ArrayList<String> ID_ArrayList = new ArrayList<String>();
ArrayList<String> NAME_ArrayList = new ArrayList<String>();
ArrayList<String> PHONE_NUMBER_ArrayList = new ArrayList<String>();
ArrayList<String> SUBJECT_ArrayList = new ArrayList<String>();
ListView LISTVIEW;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_view);
LISTVIEW = (ListView) findViewById(R.id.listView1);
SQLITEHELPER = new SQLiteHelper(this);
}
@Override
protected void onResume() {
ShowSQLiteDBdata() ;
super.onResume();
}
private void ShowSQLiteDBdata() {
SQLITEDATABASE = SQLITEHELPER.getWritableDatabase();
cursor = SQLITEDATABASE.rawQuery("SELECT * FROM demoTable", null);
ID_ArrayList.clear();
NAME_ArrayList.clear();
PHONE_NUMBER_ArrayList.clear();
SUBJECT_ArrayList.clear();
if (cursor.moveToFirst()) {
do {
ID_ArrayList.add(cursor.getString(cursor.getColumnIndex(SQLiteHelper.KEY_ID)));
NAME_ArrayList.add(cursor.getString(cursor.getColumnIndex(SQLiteHelper.KEY_Name)));
PHONE_NUMBER_ArrayList.add(cursor.getString(cursor.getColumnIndex(SQLiteHelper.KEY
_PhoneNumber)));
SUBJECT_ArrayList.add(cursor.getString(cursor.getColumnIndex(SQLiteHelper.KEY_Subject))); }
while (cursor.moveToNext());
}
ListAdapter = new SQLiteListAdapter(ListViewActivity.this,
ID_ArrayList,
NAME_ArrayList,
PHONE_NUMBER_ArrayList,
SUBJECT_ArrayList );
LISTVIEW.setAdapter(ListAdapter);
cursor.close();
}}
SQLiteHelper.java
package com.example.sqllite;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class SQLiteHelper extends SQLiteOpenHelper {
static String DATABASE_NAME="DemoDataBase";
public static final String KEY_ID="id";
public static final String TABLE_NAME="demoTable";
public static final String KEY_Name="name";
public static final String KEY_PhoneNumber="phone_number";
public static final String KEY_Subject="subject";
public SQLiteHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
}
@Override
public void onCreate(SQLiteDatabase database) {
String CREATE_TABLE="CREATE TABLE "+TABLE_NAME+" ("+KEY_ID+"
INTEGER PRIMARY KEY, "+KEY_Name+" VARCHAR, "+KEY_PhoneNumber+"
VARCHAR, "+KEY_Subject+" VARCHAR)";
database.execSQL(CREATE_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS "+TABLE_NAME);
onCreate(db);
}
}
SQLiteListAdapter.java
package com.example.sqllite;
import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class SQLiteListAdapter extends BaseAdapter {
Context context;
ArrayList<String> userID;
ArrayList<String> UserName;
ArrayList<String> User_PhoneNumber;
ArrayList<String> UserSubject ;
public SQLiteListAdapter(
Context context2,
ArrayList<String> id,
ArrayList<String> name,
ArrayList<String> phone,
ArrayList<String> subject
) {
this.context = context2;
this.userID = id;
this.UserName = name;
this.User_PhoneNumber = phone;
this.UserSubject = subject ;
}
public int getCount() {
return userID.size();
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(int position, View child, ViewGroup parent) {
Holder holder;
LayoutInflater layoutInflater;
if (child == null) {
layoutInflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
child = layoutInflater.inflate(R.layout.listviewdatalayout, null);
holder = new Holder();
holder.textviewid = (TextView) child.findViewById(R.id.textViewID);
holder.textviewname = (TextView) child.findViewById(R.id.textViewNAME);
holder.textviewphone_number = (TextView)
child.findViewById(R.id.textViewPHONE_NUMBER);
holder.textviewsubject = (TextView) child.findViewById(R.id.textViewSUBJECT);
child.setTag(holder);
} else {
holder = (Holder) child.getTag();
}
holder.textviewid.setText(userID.get(position));
holder.textviewname.setText(UserName.get(position));
holder.textviewphone_number.setText(User_PhoneNumber.get(position));
holder.textviewsubject.setText(UserSubject.get(position));
return child;
}
package com.example.emaildemo;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
private EditText eTo;
private EditText eSubject;
private EditText eMsg;
private Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
eTo = (EditText)findViewById(R.id.txtTo);
eSubject = (EditText)findViewById(R.id.txtSub);
eMsg = (EditText)findViewById(R.id.txtMsg);
btn = (Button)findViewById(R.id.btnSend);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_EMAIL, new String[]{eTo.getText().toString()});
it.putExtra(Intent.EXTRA_SUBJECT,eSubject.getText().toString());
it.putExtra(Intent.EXTRA_TEXT,eMsg.getText());
it.setType("message/rfc822");
startActivity(Intent.createChooser(it,"Choose Mail App"));
}
});
}
}
AndroidManifest.xml
MainActivity.java
package com.example.phoneservice;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.view.MenuItem;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.PopupMenu;
import android.widget.RelativeLayout;
public class MainActivity extends AppCompatActivity {
EditText edittext1;
Button btncall;
PopupMenu pop1;
RelativeLayout r1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edittext1 = (EditText) findViewById(R.id.phoneno1);
btncall = (Button) findViewById(R.id.call);
btncall.setOnClickListener(new OnClickListener() {
@SuppressLint("MissingPermission")
@Override
public void onClick(View v) {
PopMenuDisplay1();
} }); }
public void PopMenuDisplay1() {
pop1 = new PopupMenu(MainActivity.this,btncall );
pop1.getMenuInflater().inflate(R.menu.pop_up_menu, pop1.getMenu());
pop1.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@SuppressLint("MissingPermission")
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.call:
String phnumber=edittext1.getText().toString();
Intent callIntent=new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+phnumber));
startActivity(callIntent);
return true;
case R.id.sms:
Intent i = new Intent(getBaseContext(), sms.class);
startActivity(i);
return true;
} return true;
} });
pop1.show();
} }
Activity_sms.xml
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.phoneservice">
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<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=".sms"></activity>
<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>
SMS
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="282dp"
android:layout_height="174dp"
android:text="Android Phone Services - Call And SMS"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="#104B31"
android:textSize="36sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.496"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.067" />
<EditText
android:id="@+id/phoneno1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="52dp"
android:ems="10"
app:layout_constraintBottom_toTopOf="@+id/call"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:layout_constraintVertical_bias="0.538" />
<Button
android:id="@+id/call"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="184dp"
android:text="options"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.544"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
</androidx.constraintlayout.widget.ConstraintLayout>
Pop_up_menu.xml
MainActivity.java
package com.example.phoneservice;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.view.MenuItem;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.PopupMenu;
import android.widget.RelativeLayout;
public class MainActivity extends AppCompatActivity {
EditText edittext1;
Button btncall;
PopupMenu pop1;
RelativeLayout r1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edittext1 = (EditText) findViewById(R.id.phoneno1);
btncall = (Button) findViewById(R.id.call);
btncall.setOnClickListener(new OnClickListener() {
@SuppressLint("MissingPermission")
@Override
public void onClick(View v) {
PopMenuDisplay1();
} }); }
public void PopMenuDisplay1() {
pop1 = new PopupMenu(MainActivity.this,btncall );
pop1.getMenuInflater().inflate(R.menu.pop_up_menu, pop1.getMenu());
pop1.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@SuppressLint("MissingPermission")
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.call:
String phnumber=edittext1.getText().toString();
Intent callIntent=new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+phnumber));
startActivity(callIntent);
return true;
case R.id.sms:
Intent i = new Intent(getBaseContext(), sms.class);
startActivity(i);
return true;
} return true;
} });
pop1.show();
} }
Activity_sms.xml
package com.example.phoneservice;
import androidx.appcompat.app.AppCompatActivity;
import android.app.PendingIntent;
import android.content.Intent;
import android.telephony.SmsManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.os.Bundle;
public class sms extends AppCompatActivity {
EditText mobileno,message;
Button sendsms;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sms);
mobileno=(EditText)findViewById(R.id.phoneno1);
message=(EditText)findViewById(R.id.editText2);
sendsms=(Button)findViewById(R.id.button1);
mobileno.setText(mobileno.getText());
sendsms.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
String no=mobileno.getText().toString();
String msg=message.getText().toString();
Intent intent=new Intent(getApplicationContext(),MainActivity.class);
PendingIntent pi=PendingIntent.getActivity(getApplicationContext(), 0, intent,0);
SmsManager sms=SmsManager.getDefault();
sms.sendTextMessage(no, null, msg, pi,null);
Toast.makeText(getApplicationContext(), "Message Sent successfully!",
Toast.LENGTH_LONG).show();
} }); }
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.phoneservice">
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<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=".sms"></activity>
<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>