Samar Ap LabFile
Samar Ap LabFile
SUBMITTED BY:
Student Name: Samar Bezbaruah
Roll Number: 07
GU Roll Number: UA-211-033-1150
Registration Number: 21009903
BVoc IT 6th Semester
COURSE INSTRUCTOR:
Jyotishman Das
Guest lecturer
PUB KAMRUP COLLEGE, BAIHATA CHARIALI
---INDEX---
SL. NO NAME OF THE PROGRAM PAGE NO
01 Hello world! 01-02
02 Text & Scroll View 03-04
03 Camera Permission 05-10
04 Fragment Implement 11-18
05 Create an application with two field (numbers 1 , numbers 2 ) .on clicking 19-23
button the sum of the two number are displayed on another text field.
06 Create a login application with two fields’ username and password. On 24-31
successful login go to next screen, also pass the username to the next
screen. Also on failed login alert user using toast
07 Create an application a spinner with name of some country. On selecting a 32-34
particular country. Display a toast message with currency name of that
country
08 Create an application with a button on the clicking button web browser with 35-38
an URL(open google page)
09 Create an android application to display internal storage data using Array. 39-41
Program No 1: HELLO WORLD!
ActivityMain.xml
<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/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#091971"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textColor="#1BCC22"
android:textSize="48sp"
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:
2nd Program: TextAndScrolling Views
MainActivity.xml
<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:background="#2196F3"
tools:context=".MainActivity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="UselessParent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/article_gallery"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="4">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageView"
android:layout_width="203dp"
android:layout_height="222dp"
android:layout_gravity="center"
android:layout_weight="1"
app:srcCompat="@drawable/pub" />
</LinearLayout>
OUTPUT:
Program 3: Camera Permissions
MainActivity.java
package com.example.photo;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = findViewById(R.id.imageview);
button=findViewById(R.id.button);
Manifest.permission.CAMERA)
!=PackageManager.PERMISSION_GRANTED) {
Manifest.permission.CAMERA
},100);
@Override
startActivityForResult(intent, 100);
});
@Override
data) {
if (requestCode == 100){
imageView.setImageBitmap(bitmap);
}
}
activity_main.xml
<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">
<ImageView
android:layout_weight="1"
android:id="@+id/imageview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/design_default_color_primary"
android:text="CAPTURE AN IMAGE"
android:textColor="#ffffff"
android:textStyle="bold" />
<TextView
android:id="@+id/image_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_marginBottom="300dp"
android:textColor="#131212"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Photo"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
</intent-filter>
</activity>
</application>
</manifest>
OUTPUT:
Program 4: Fragment
MainActivity.java
package com.example.fragment;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.tabs.TabLayout;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSectionsPagerAdapter = new
SectionsPagerAdapter(getSupportFragmentManager());
mViewPager = findViewById(R.id.viewPager);
mViewPager.setAdapter(mSectionsPagerAdapter);
TabLayout tabLayout = findViewById(R.id.tabLayout);
tabLayout.setupWithViewPager(mViewPager);
super(fm);
@Override
switch (position) {
case 0:
case 1:
case 2:
default:
return null;
@Override
return 3;
}
@Override
switch (position) {
case 0:
case 1:
case 2:
return null;
activity.main.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabSelectedTextColor="@android:color/holo_red_dark">
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</com.google.android.material.tabs.TabLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
Fragment_1.java
package com.example.fragment;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public Fragment1() {
}
@Override
Bundle savedInstanceState) {
Fragment_2.java
package com.example.fragment;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public Fragment2() {
@Override
Bundle savedInstanceState) {
}
Fragment_3.java
package com.example.fragment;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public Fragment3() {
@Override
Bundle savedInstanceState) {
fragment_1.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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_centerInParent="true"
android:textColor="@android:color/holo_red_dark"
android:textSize="30dp"
android:textStyle="bold" />
</RelativeLayout>
fragment_2.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/holo_orange_dark"
android:textSize="30dp"
android:textStyle="bold"
android:layout_centerInParent="true"/>
</RelativeLayout>
fragment_3.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="@android:color/holo_blue_bright"
android:textSize="30dp"
android:textStyle="bold" />
</RelativeLayout>
OUTPUT:
Program 5 : Create an application with two field (numbers 1 , numbers 2
) .on clicking button the sum of the two number are displayed on
another text field.
ActivityMain.java
package com.fms.addtwonos;
import android.os.Bundle;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
EditText number1;
EditText number2;
Button Add_button;
TextView result;
int ans=0;
@Override
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
number1=(EditText) findViewById(R.id.editText_first_no);
number2=(EditText) findViewById(R.id.editText_second_no);
Add_button=(Button) findViewById(R.id.add_button);
Add_button.setOnClickListener(new View.OnClickListener() {
result.setText(Double.toString(sum));
});
}
ActivityMain.xml
<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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView_answer"
android:layout_width="100dp"
android:layout_height="25dp"
android:text="0"
android:layout_marginLeft="130dp"
android:layout_marginTop="300dp"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:id="@+id/textView_first_no"
android:layout_width="150dp"
android:layout_height="25dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="50dp"
android:text="First number"
android:textSize="20dp"/>
<EditText
android:id="@+id/editText_first_no"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_marginLeft="200dp"
android:layout_marginTop="40dp"
android:inputType="number"
/>
<TextView
android:id="@+id/textView_second_no"
android:layout_width="150dp"
android:layout_height="25dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="100dp"
android:text="Second number"
android:textSize="20dp" />
<EditText
android:id="@+id/editText_second_no"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_marginLeft="200dp"
android:layout_marginTop="90dp"
android:inputType="number"
/>
<Button
android:id="@+id/add_button"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_marginLeft="110dp"
android:layout_marginTop="200dp"
android:text="Add"/>
</RelativeLayout>
OUTPUT:
Program 6: create a login application with two fields username and
password . on successful login go to next screen ,also pass the username
to the next screen . also on failed login alert user using toast.
MainActivity.java
package com.parse.hellologin;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
usernameEditText = findViewById(R.id.idEdtUserName);
passwordEditText = findViewById(R.id.idEdtPassword);
loginButton = findViewById(R.id.idBtnLogin);
@Override
password, Toast.LENGTH_SHORT).show();
} else {
Toast.LENGTH_SHORT).show();
});
activity_main.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!--text view for heading-->
<TextView
android:id="@+id/idTVHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:gravity="center_horizontal"
android:padding="5dp"
android:textAlignment="center"
android:textColor="@android:color/holo_blue_bright"
android:textSize="30dp" />
<EditText
android:id="@+id/idEdtUserName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/idTVHeader"
android:layout_marginStart="10dp"
android:layout_marginTop="50dp"
android:layout_marginEnd="10dp"
android:hint="Enter UserName"
android:inputType="textEmailAddress" />
<EditText
android:id="@+id/idEdtPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/idEdtUserName"
android:layout_marginStart="10dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="10dp"
android:hint="Enter Password"
android:inputType="textPassword" />
<Button
android:id="@+id/idBtnLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/idEdtPassword"
android:layout_marginStart="10dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="10dp"
android:text="Login"
android:textAllCaps="false" />
</RelativeLayout>
SecondActivity.java
package com.parse.hellologin;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
usernameTextView = findViewById(R.id.idTVUserName);
logoutButton = findViewById(R.id.idBtnLogout);
usernameTextView.setText(username);
logoutButton.setOnClickListener(new View.OnClickListener() {
@Override
});
activity_second.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SecondActivity">
<TextView
android:id="@+id/idTVHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center_horizontal"
android:textAlignment="center"
android:textColor="@android:color/holo_blue_bright"
android:textSize="18sp" />
<TextView
android:id="@+id/idTVUserName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/idTVHeader"
android:layout_centerInParent="true"
android:layout_marginTop="20dp"
android:gravity="center_horizontal"
android:text="UserName"
android:textAlignment="center"
android:textColor="@android:color/holo_blue_bright"
android:textSize="25sp" />
<Button
android:id="@+id/idBtnLogout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/idTVUserName"
android:layout_centerInParent="true"
android:layout_marginTop="10dp"
android:text="LogOut"
android:textAllCaps="false" />
</RelativeLayout>
OUTPUT:
Program 7: Create an application a spinner with name of some country,
on selecting a particular country. Display a toast message with currency
name of that country.
MainActivity.java
package com.example.spinner;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
AdapterView.OnItemSelectedListener {
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
spin.setOnItemSelectedListener(this);
ArrayAdapter aa = new
ArrayAdapter(this,android.R.layout.simple_spinner_item,country);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(aa);
}
//Performing action onItemSelected and onNothing selected
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) {
Toast.makeText(getApplicationContext(),country[position] ,
Toast.LENGTH_LONG).show();
@Override
}}
activity_main.xml
<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">
<Spinner android:id="@+id/spinner"
android:layout_width="149dp"
android:layout_height="40dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.498" />
</androidx.constraintlayout.widget.ConstraintLayout>
OUTPUT:
Program 8: Create an application with a button on the clicking button
web browser with an URL (open Google page).
ActivityMain.xml
<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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:id="@+id/layout">
<TextView
android:textSize="20dp"
android:layout_marginTop="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="https://www."
android:id="@+id/textview" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/urltxt"
android:textColor="@color/black"
android:layout_marginEnd="20dp"
android:layout_centerInParent="true"
android:alpha="0.7"
android:textSize="20dp"
android:padding="10dp" />
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="submit"
android:layout_below="@+id/layout"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:id="@+id/gotoURL" />
</RelativeLayout>
ActivityMain.java
import android.os.Bundle;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import android.content.Intent;
import android.net.Uri;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
EditText editText;
Button button;
TextView textView;
@Override
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
editText = findViewById(R.id.urltxt);
button = findViewById(R.id.gotoURL);
textView = findViewById(R.id.textview);
return insets;
});
}
OUTPUT:
Program 9: Create an android application to display internal storage data
using Array.
MainActivity.java
package com.fms.mylistview;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;
import java.io.File;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] items = {
"SHAREit",
"Android",
"mbstph",
"Playlists",
"IMO",
"emp11am.json",
"Pictures",
"VuCrash.txt",
"Sounds",
"Download",
"DCIM"
};
ArrayAdapter<String> adapter;
androidx.constraintlayout.widget.R.layout.support_simple_spinner_dropdown_item,items);
listView.setAdapter(adapter);
activity_main.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#009688"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginRight="5dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#2B2D30"
android:text="LISTVIEW!"
android:textColor="@color/white"
android:textSize="30dp"
android:textStyle="italic" />
<ListView
android:id="@+id/lview"
android:layout_width="match_parent"
android:layout_height="match_parent"></ListView>
</LinearLayout>
OUTPUT: