Practical 6 Aim:-Using An Intent To Go To Next Activity Java Code: Mainactivity - Java

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

IU2041231195 Mobile Application Development Sem-VI

Practical 6
Aim:- using an Intent to go to next activity
Java Code :
MainActivity.java
public class MainActivity extends AppCompatActivity {
Button b;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

b = findViewById(R.id.btn);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(MainActivity.this ,
Secondactivity.class);
startActivity(i);
}
});

}
}

Activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout

xmlns:android="http://schemas.android.com/apk/r
es/android"

INDUS UNIVERSITY 1
IU2041231195 Mobile Application Development Sem-VI

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"
android:background="@color/purple_200">

<Button
android:id="@+id/btn"
android:text="Take to nxt screen"
android:gravity="center"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

</RelativeLayout>

OutPut :

INDUS UNIVERSITY 2
IU2041231195 Mobile Application Development Sem-VI

Practical 7
Aim : create the menu in android
Code :
MainActivity.java :-
package com.example.collegepractical;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
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.menu,
menu);
return true;
}

INDUS UNIVERSITY 3
IU2041231195 Mobile Application Development Sem-VI

public boolean
onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId()) {
case R.id.message:
Toast
.makeText(

getApplicationContext(),
"Shows share
icon",

Toast.LENGTH_SHORT)
.show();
return true;

case R.id.picture:
Toast
.makeText(

getApplicationContext(),
"Shows image
icon",

Toast.LENGTH_SHORT)
.show();

return (true);

case R.id.mode:
Toast
.makeText(

getApplicationContext(),
"Shows call
icon",

Toast.LENGTH_SHORT)
.show();
return (true);

case R.id.about:
Toast
.makeText(

INDUS UNIVERSITY 4
IU2041231195 Mobile Application Development Sem-VI

getApplicationContext(),
"calculator
menu",

Toast.LENGTH_SHORT)
.show();
return (true);

case R.id.exit:
finish();
return (true);
}
return
(super.onOptionsItemSelected(item));
}
}

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

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"
tools:context=".MainActivity">

<item
android:id="@+id/message"
android:icon="@android:drawable/ic_menu_send"
app:showAsAction="always"
android:title="message"/>

<item
android:id="@+id/picture"
android:icon="@android:drawable/ic_menu_gallery"
app:showAsAction="always|withText"
android:title="picture"/>

<item
android:id="@+id/mode"
android:icon="@android:drawable/ic_menu_call"
app:showAsAction="always"
android:title="mode"/>

<item
android:id="@+id/about"
android:icon="@android:drawable/ic_dialog_info"
INDUS UNIVERSITY 5
IU2041231195 Mobile Application Development Sem-VI

app:showAsAction="never|withText"
android:title="calculator"/>

<item
android:id="@+id/exit"
app:showAsAction="never"
android:title="exit"/>
</menu>

OutPut :-

INDUS UNIVERSITY 6
IU2041231195 Mobile Application Development Sem-VI

Practical - 8
Aim : SMS send to phone in android
Code :
MainActivity.java :-
package com.example.collegepractical;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


EditText phone,msg;
Button bt;

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

phone = findViewById(R.id.phone);
msg = findViewById(R.id.msg);
bt = findViewById(R.id.send);

bt.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View view) {
if (Build.VERSION.SDK_INT >=
Build.VERSION_CODES.M)
{
INDUS UNIVERSITY 7
IU2041231195 Mobile Application Development Sem-VI

if
(checkSelfPermission(Manifest.permission.SEND_SMS) ==
PackageManager.PERMISSION_GRANTED)
{
sendSms();
}
else
{
requestPermissions(new
String[]{

Manifest.permission.SEND_SMS
} , 1);
}
}
}
});
}

private void sendSms() {


String phoneNo =
phone.getText().toString().trim();
String SMS = msg.getText().toString().trim();

try {
SmsManager smsManager =
SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo , null ,
SMS , null , null);

Toast.makeText(this, "Message is sent",


Toast.LENGTH_SHORT).show();

}
catch (Exception e)
{
e.printStackTrace();
Toast.makeText(this, "Fail to some
message", Toast.LENGTH_SHORT).show();
}
}

INDUS UNIVERSITY 8
IU2041231195 Mobile Application Development Sem-VI

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"
tools:context=".MainActivity"
android:orientation="vertical">

<EditText
android:id="@+id/phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="PhoneNumber"
android:inputType="phone"
android:gravity="center"
android:layout_margin="25dp"
/>

<EditText
android:id="@+id/msg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="msg"
android:inputType="textLongMessage"
android:gravity="center"
android:layout_margin="25dp"
/>

<Button
android:id="@+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Done"/>

</LinearLayout>

INDUS UNIVERSITY 9
IU2041231195 Mobile Application Development Sem-VI

OutPut : ---

INDUS UNIVERSITY 10
IU2041231195 Mobile Application Development Sem-VI

Practical – 9
Aim : Create map in android
Code :
MainActivity :-
package com.example.googlemaps;

import androidx.fragment.app.FragmentActivity;

import android.os.Bundle;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import
com.example.googlemaps.databinding.ActivityMapsBinding;

public class MapsActivity extends FragmentActivity


implements OnMapReadyCallback {

private GoogleMap mMap;


private ActivityMapsBinding binding;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

binding =
ActivityMapsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

// Obtain the SupportMapFragment and get


notified when the map is ready to be used.
SupportMapFragment mapFragment =
(SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}

/**
* Manipulates the map once available.
* This callback is triggered when the map is ready
INDUS UNIVERSITY 11
IU2041231195 Mobile Application Development Sem-VI

to be used.
* This is where we can add markers or lines, add
listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the
device, the user will be prompted to install
* it inside the SupportMapFragment. This method
will only be triggered once the user has
* installed Google Play services and returned to
the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;

// Add a marker in Sydney and move the camera


LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new
MarkerOptions().position(sydney).title("Marker in
Sydney"));

mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}

Activity_main.xml :-
<fragment
xmlns:android="http://schemas.android.com/apk/res/andro
id"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"

android:name="com.google.android.gms.maps.SupportMapFra
gment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity" />

INDUS UNIVERSITY 12
IU2041231195 Mobile Application Development Sem-VI

OutPut :

INDUS UNIVERSITY 13
IU2041231195 Mobile Application Development Sem-VI

Practical – 10
Aim : Playing video file in android
Code :
MainActivity.java :
public class MainActivity extends AppCompatActivity {
String s =
"C:\\Users\\shapa\\Downloads\\Video\\video.mkv";

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

VideoView videoView =
findViewById(R.id.videoView);

MediaController mediaController = new


MediaController(this);
mediaController.setAnchorView(videoView);

Uri uri =
Uri.parse(Environment.getExternalStorageDirectory().getPa
th()+s);

videoView.setMediaController(mediaController);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();
}
}

Activity_main.xml :-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout

xmlns:android="http://schemas.android.com/apk/re
s/android"

xmlns:app="http://schemas.android.com/apk/res-
auto"

INDUS UNIVERSITY 14
IU2041231195 Mobile Application Development Sem-VI

xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<VideoView
android:id="@+id/videoView"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>

OutPut :

INDUS UNIVERSITY 15
IU2041231195 Mobile Application Development Sem-VI

Practical – 11
Aim : Style Demo in android
Code :
MainActivity.java :
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

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

<TextView
android:id="@+id/textView"
style="@style/CustomFontStyle"
android:text="Divya Shaparia"
android:layout_centerHorizontal="true"/>

<Button
android:id="@+id/button"
android:text="Click ME"
style="@style/CustomFontStyle"
android:layout_centerInParent="true"/>
</RelativeLayout>

Themes :
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
INDUS UNIVERSITY 16
IU2041231195 Mobile Application Development Sem-VI

<style name="Theme.CollegePractical"
parent="Theme.AppCompat.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item
name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item
name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor"
tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
<style name="CustomFontStyle">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:capitalize">characters</item>
<item name="android:typeface">monospace</item>
<item name="android:textSize">12pt</item>
<item name="android:background">#00ff00</item>
<item name="android:textColor">#FFFFFF</item>

</style>
</resources>

INDUS UNIVERSITY 17
IU2041231195 Mobile Application Development Sem-VI

Practical – 12
Aim : Radio button in IOS
Code :
Radio button in iOS <!DOCTYPE html>
<html>
<head>
<meta name = "viewport" content = "width = device-
width, initial-scale = 1,
maximum-scale = 1, minimum-scale = 1, user-scalable =
no, minimal-ui" /> <meta name = "apple-mobile-web-
app-capable" content = "yes" />
<meta name = "apple-mobile-web-app-status-bar-style"
content = "black" /> <title>Checkboxes group</title>
<link rel = "stylesheet"
href =
"https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4
.2/css/framework7.ios.
min.css" />
<link rel = "stylesheet"
href =
"https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4
.2/css/framework7.ios. colors.min.css" />
</head>
<body>
<div class = "views">
<div class = "view view-main"> <div class = "pages">
INDUS UNIVERSITY 18
IU2041231195 Mobile Application Development Sem-VI

<div data-page = "home" class = "page navbar-fixed">


<div class = "navbar">
<div class = "navbar-inner">
<div class = "left"> </div>
<div class = "center">Radios Group</div> <div class =
"right"> </div>
</div> </div>
<div class = "page-content">

<div class = "content-block-title">Select any one</div>


<div class = "list-block">
<ul> <li>
<label class = "label-radio item-content">
<input type = "radio" name = "ks-radio" value = "Java"
checked> <div class = "item-inner">
<div class = "item-title">Java</div> </div>
</label> </li>
<li>
<label class = "label-radio item-content">
<input type = "radio" name = "ks-radio" value =
"Andriod"> <div class = "item-inner">
<div class = "item-title">Andriod</div> </div>
</label> </li>
<li>
<label class = "label-radio item-content">
<input type = "radio" name = "ks-radio" value =
"Oracle"> <div class = "item-inner">
INDUS UNIVERSITY 19
IU2041231195 Mobile Application Development Sem-VI

<div class = "item-title">Oracle</div> </div>


</label> </li>
<li>
<label class = "label-radio item-content">
<input type = "radio" name = "ks-radio" value =
"Python"> <div class = "item-inner">

<div class = "item-title">Python</div> </div>


</label> </li>
</ul> </div>
</div>
</div> </div>
</div> </div>
<script type = "text/javascript"
src =
"https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4
.2/js/framework7.min.js
"></script>
<script>
var myApp = new Framework7();
</script> </body>
</html>

INDUS UNIVERSITY 20
IU2041231195 Mobile Application Development Sem-VI

OutPut :

INDUS UNIVERSITY 21

You might also like