Lab Manual of Practical - II (Android + Cyber)
Lab Manual of Practical - II (Android + Cyber)
Theory : For creating android application that display “Hello World”, need to
follow these steps :
1. Project Setup :
• Begin by setting up a new project in Android Studio. Provide a name,
package name, and choose a target SDK version.
Program :
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"
android:background="#000000"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="32dp"
android:textColor="#ff0000"
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 : We have successfully created the android application, that displaying the
"Hello World" text in the center of the screen with red text colour on a black
background.
Practical - 2
Aim : To create an Android application that can Receive SMS Messages in virtual
device.
For creating an Android application that can receive SMS messages in our virtual
device, we follow these steps :
4. Implement BroadcastReceiver :
• Create a new Java or class that extends BroadcastReceiver.
• Override the onReceive() method to handle incoming SMS messages.
• Inside the onReceive() method, extract the SMS message data and
perform any required processing.
8. Testing :
• Deploy the application to the virtual device.
• Use the virtual device's settings to send an SMS message to the virtual
device's own number.
• Verify that the BroadcastReceiver successfully receives and processes
the incoming SMS message.
Program :
activity_main.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"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SMS Receiver Application"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="@color/blue"
/>
</RelativeLayout>
smsreceiver.java :
package com.example.smsreceive;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.util.Log;
AndroidManifest.xml :
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
Output :
Result : We have successfully created the android application, that can Receive SMS
Message in our virtual device.
Practical - 3
Aim : To create an Android Application that Implement Date Picker View in android
studio.
Theory : The Date Picker View in Android provides a user-friendly interface for
selecting dates. It allows users to navigate through months and years to pick the
desired date. It is a crucial component in applications where date selection is a
common requirement, such as in calendar apps, scheduling apps, or booking systems.
For implementing Date Picker View application in Android Studio. We follow these
steps :
Program :
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"
android:gravity="center"
android:padding="20dp"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date Picker App"
android:textStyle="bold"
android:textSize="20dp"
android:textColor="@color/blue"
/>
<DatePicker
android:id="@+id/datePicker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:calendarViewShown="false"
android:datePickerMode="spinner" />
<Button
android:id="@+id/btnSubmit"
android:text="Save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
MainActivity.java
package com.example.datepickerapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.Toast;
DatePicker datepicker;
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
datepicker = findViewById(R.id.datePicker);
button = findViewById(R.id.btnSubmit);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String day, month, year;
day = String.valueOf(datepicker.getDayOfMonth());
month = String.valueOf(datepicker.getMonth() + 1);
year = String.valueOf(datepicker.getYear());
Toast.makeText(MainActivity.this, day + "/" + month + "/" +
year + " Date Pick Successfully", Toast.LENGTH_SHORT).show();
}
});
}
}
Output :
Result : We have successfully implemented the Date Picker View android application in
the virtual or physical device.
Practical - 4
Aim : To create an Android Application that Implement Time Picker View in android
studio.
Theory : The Time Picker View in Android provides a user-friendly interface for
selecting time values. It allows users to adjust hours and minutes using a spinner or a
clock-style interface, depending on the version of Android. Time Picker Views are
commonly used in applications where time selection is required, such as alarm clock
apps, scheduling apps, or reminder apps.
For implementing Time Picker View application in Android Studio. We follow these
steps :
1. Set Up Project :
• Create a new Android project in Android Studio.
• Define the project details such as the package name, activity name, and
other configurations.
Program :
activity_main.xml
<TextView
android:id="@+id/timetxtview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your Time Displays Here"
android:textSize="20sp"
android:layout_marginTop="300dp"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Pick Time"
android:textSize="20sp"
android:id="@+id/picktime"
android:layout_marginTop="350sp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
/>
</RelativeLayout>
MainActivity.java
package com.example.timepickerviewapp;
import androidx.appcompat.app.AppCompatActivity;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TimeTextView=findViewById(R.id.timetxtview);
PickTime=findViewById(R.id.picktime);
PickTime.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Calendar calender = Calendar.getInstance();
int hours = calender.get(Calendar.HOUR_OF_DAY);
int mins = calender.get(Calendar.MINUTE);
TimePickerDialog timePickerDialog = new
TimePickerDialog(MainActivity.this,
androidx.appcompat.R.style.Theme_AppCompat_Dialog, new
TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay,
int minute) {
Calendar c = Calendar.getInstance();
c.set(Calendar.HOUR_OF_DAY,hourOfDay);
c.set(Calendar.MINUTE,minute);
c.setTimeZone(TimeZone.getDefault());
SimpleDateFormat format = new
SimpleDateFormat("k:mm a");
String time = format.format(c.getTime());
TimeTextView.setText(time);
}
},hours, mins, false);
timePickerDialog.show();
}
});
}
}
Output :
Result : We have successfully implemented the Time Picker View android application in
the virtual or physical device.
Practical - 5
Aim : To create a program in Android Studio to Implement web view.
Program :
<?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">
<WebView
android:id="@+id/wv"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
MainActivity.java
package com.example.webview;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.wv);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("https://www.amazon.in/");
}
@Override
public void onBackPressed() {
if (webView.canGoBack()){
webView.goBack();
}else {
super.onBackPressed();
}
}
}
AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
Output :
Result : We have successfully implemented the Web View in the virtual or physical device.
Practical - 6
Aim : To create a program in Android Studio to Implement Image switcher view.
Theory : The Image Switcher view in Android enables smooth transitioning between
images, enhancing visual appeal and user engagement. It's utilized for creating image
galleries, slideshows, and applications requiring dynamic image switching, offering
smooth animation support.
For implementing Image Switcher View in Android Studio. We follow these steps :
3. Prepare Images : Add more than 4 images to the project's drawable folder.
Program :
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:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="150dp"
android:textSize="30sp"
android:textColor="#000000"
android:textStyle="italic"
android:text="Image Switcher App"
/>
<ImageSwitcher
android:id="@+id/ImgSwitch"
android:layout_margin="20dp"
android:layout_width="match_parent"
android:layout_centerVertical="true"
android:layout_height="250dp"
/>
<Button
android:id="@+id/prev"
android:text="Prev"
android:layout_below="@+id/ImgSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/nxt"
android:text="Next"
android:layout_below="@+id/ImgSwitch"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</RelativeLayout>
MainActivity.java
package com.example.imageswitcherview;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ViewSwitcher;
int index = 0;
int cars[]={R.drawable.a1,R.drawable.a2,R.drawable.a3,R.drawable.a4};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImgSwitch = findViewById(R.id.ImgSwitch);
prev = findViewById(R.id.prev);
nxt = findViewById(R.id.nxt);
ImgSwitch.setFactory(new ViewSwitcher.ViewFactory() {
@Override
public View makeView() {
ImageView imageView = new
ImageView(getApplicationContext());
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
imageView.setMaxHeight(250);
imageView.setMaxWidth(250);
return imageView;
}
});
ImgSwitch.setImageResource(cars[index]);
prev.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
--index;
if (index<0){
index=cars.length-1;
}
ImgSwitch.setImageResource(cars[index]);
}
});
nxt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
index++;
if(index==cars.length){
index=0;
}
ImgSwitch.setImageResource(cars[index]);
}
});
}
}
Output :
Result : We have successfully implemented the Image Switcher View in the virtual
or physical device.
Practical - 7
Aim : To create a program in Android Studio to Implement Image Scroll View.
Theory : The ScrollView in Android provides a container that enables scrolling of its
contents vertically or horizontally when the content exceeds the available screen space.
It allows users to view and interact with content that may not fit entirely on the screen.
We utilize ScrollView to accommodate large amounts of text, images, or other UI
elements within limited screen dimensions. This feature enhances usability by ensuring
that users can access all content regardless of screen size.
For implementing Image Scroll View in Android Studio. We follow these steps :
2. Prepare Images and Text : Prepare five different images and corresponding
text for each image.
5. Enable Scrolling : Ensure that the ScrollView is enabled for scrolling vertically.
Program :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_marginHorizontal="15dp"
android:layout_marginTop="15dp"
android:src="@drawable/b1"
android:scaleType="centerCrop" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="5dp"
android:text="Blue Water"
android:textSize="20dp"
android:textStyle="bold" />
<ImageView
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_marginHorizontal="15dp"
android:layout_marginTop="15dp"
android:src="@drawable/b2"
android:scaleType="centerCrop" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="5dp"
android:text="Sunset"
android:textSize="20dp"
android:textStyle="bold" />
<ImageView
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_marginHorizontal="15dp"
android:layout_marginTop="15dp"
android:src="@drawable/b3"
android:scaleType="centerCrop" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="5dp"
android:text="Anime Nature"
android:textSize="20dp"
android:textStyle="bold" />
<ImageView
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_marginHorizontal="15dp"
android:layout_marginTop="15dp"
android:src="@drawable/b4"
android:scaleType="centerCrop" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="5dp"
android:text="Orange View"
android:textSize="20dp"
android:textStyle="bold" />
<ImageView
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_marginHorizontal="15dp"
android:layout_marginTop="15dp"
android:src="@drawable/b5"
android:scaleType="centerCrop" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="5dp"
android:text="Japnese Landscape"
android:textSize="20dp"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
Output :
Result : We have successfully implemented the Image Sroll View in the virtual or physical
device.
Practical - 8
Aim : To create a program in Android Studio to Implement a calling service.
1. Create a New Project : Open Android Studio and create a new project.
Choose a suitable project name and select the Empty Activity template.
2. Design the Layout : Open the activity_main.xml file from the res/layout
directory. Design the user interface (UI) for our app. We'll need a EditText for
entering the phone number and a Button for initiating the call.
<uses-permission android:name="android.permission.CALL_PHONE"/>
4. Handle Button Click : In the MainActivity.java file, write code to handle the
button click event. When the user clicks the button, we will need to retrieve
the phone number from the EditText and initiate a phone call using the Intent
class.
5. Request Permission : Since we are targeting Android 6.0 (API level 23) or
higher, we need to request the CALL_PHONE permission at runtime. Check if
the permission is granted, and if not, request it.
7. Test : Run our app on an emulator or a real device. Enter a phone number and
click the call button to verify that the app can make calls successfully.
Program :
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"
tools:context=".MainActivity"
android:gravity="center"
android:padding="20dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calling Application"
android:textSize="30dp"
android:textStyle="bold"
android:textColor="@color/Blue"
android:layout_marginBottom="75dp"/>
<EditText
android:id="@+id/pn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter_phone_number"
android:textSize="20dp"
android:textAlignment="center"
android:inputType="phone"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/call"
android:onClick="CallToNumber"
android:layout_marginTop="90dp"
android:textStyle="bold"
android:background="@color/Blue"
/>
</LinearLayout>
MainActivity.java
package com.example.callingserviceapp;
import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
phoneno=(EditText) findViewById(R.id.pn);
}
}
else
{
ActivityCompat.requestPermissions(MainActivity.this, new
String[]{Manifest.permission.CALL_PHONE}, REQUEST_CALL_CODE);
}
}
}
Androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-feature
android:name="android.hardware.telephony"
android:required="true" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
<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.CallingServiceApp"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
</application>
</manifest>
Output :
Result : We have successfully implemented the Calling Service in our physical device.
Practical - 9
Aim : To create a program in Android Studio to Implement text-to-speech service.
1. Create a New Project : Open Android Studio and create a new project with
an appropriate name.
2. Design the Layout : Design the user interface (UI) for our app. We'll need an
EditText for entering text input and a Button to trigger the text-to-speech
conversion. Open the activity_main.xml file from the res/layout directory and
design the layout accordingly.
7. Test : Run our app on physical device. Enter text input and click the Button to
verify that the app converts the text to speech successfully.
Program :
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">
<EditText
android:id="@+id/edittxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="200dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:ems="10"
android:inputType="textMultiLine"
android:lines="5"
/>
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Convert to Speech"
android:layout_centerHorizontal="true"
android:layout_marginTop="500dp"
android:textAlignment="center"
/>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text to Speech Converter"
android:textColor="@color/blue"
android:textSize="20dp"
android:textStyle="bold"
android:layout_centerHorizontal="true"
android:layout_marginTop="200dp"
/>
</RelativeLayout>
MainActivity.java
package com.example.texttospeechserviceapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import java.util.Locale;
TextToSpeech tts;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText e1 = findViewById(R.id.edittxt);
Button b1 = findViewById(R.id.btn);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
tts = new TextToSpeech(getApplicationContext(), new
TextToSpeech.OnInitListener() {
@Override
public void onInit(int i) {
if (i==TextToSpeech.SUCCESS){
tts.setLanguage(Locale.US);
tts.setSpeechRate(1.0f);
tts.speak(e1.getText().toString(),TextToSpeech.QUEUE_ADD,null);
}
}
});
}
});
}
}
Output :
Theory : For implementing Camera View in Android Studio. We have to follow steps:
2. Design the Layout: Design the user interface (UI) for our app. We'll need a
layout with an ImageView to display the captured image and a Button to open
the camera and capture photos. Open the activity_main.xml layout file and
design the layout accordingly.
4. Open Camera and Capture Photo : Implement the functionality to open the
camera and capture photos when the user clicks the button. We'll need to use
the Camera ImageCapture use case to capture images.
6. Test : Run our app on an physical device. Verify that we can open the camera,
capture photos, and display them in the ImageView successfully.
Program :
Activity_main.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:gravity="center"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textSize="20dp"
android:textColor="@color/blue"
android:text="Camera View App"
android:textStyle="bold" />
<ImageView
android:id="@+id/imgcamera"
android:layout_marginTop="40dp"
android:layout_width="500dp"
android:layout_height="500dp"
android:background="@color/grey"
android:scaleType="fitXY" />
<Button
android:id="@+id/btncamera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="550dp"
android:layout_centerHorizontal="true"
android:text="Open Camera" />
</RelativeLayout>
MainActivity.java
package com.example.cameraviewapp;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
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
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btncamera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new
Intent(MediaStore.ACTION_IMAGE_CAPTURE_SECURE);
startActivityForResult(intent, 101, null);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
@Nullable Intent data) {
Output :
Result : We have successfully implemented the Camera View in our physical device.
Practical – 11
Datapipe
A port redirection tool functions as a conduit for TCP/IP connections. For example, you could
place a datapipe on a system between a browser and a web server. If you pointed the browser
to the listening port of the system with the redirection tool, the browser would see the contents
of the web server without having to directly access the web server’s IP address. redirection tool
passes TCP/IP traffic received by the tool on one port to another port to which the tool points.
Datapipe is not exploit code. It is not a buffer overflow or a cross-site scripting attack. For all
the scenarios mentioned in these examples, command-line access is a prerequisite on the server
running the port redirection tool.
Using Datapipe is straightforward in spite of the complicated port redirection tunnels that you
can create with it:
$ ./datapipe
Usage: ./datapipe localhost localport remotehost remoteport
• The localhost argument indicates the IP address on which to open the listening port. It
may be the localhost interface (i.e., 127.0.0.1) or the address of a network interface on the local
system from which the datapipe command is being executed.
• The localport argument indicates the listening port on the local system; connections
will be made to this port number. On Unix systems, you must have root privileges to open a
listening port below 1024. If you receive an error similar to “bind: Permission denied,” your
account may not have privileges to open a reserved port.
• The remoteport argument indicates the port to which data is to be forwarded. For
example, in most cases if the target is a web server, the remoteport value will be 80.
• The remotehost argument indicates the hostname or IP address of the target.
The easiest conceptual example of port redirection is forwarding HTTP traffic. Here we set up
a datapipe to listen on a high port, 9080 in this example, that redirects to a web site of our
choice:
You should see Google’s home page. By design, Datapipe places itself in the background. So
we’ll have to use the ps and kill commands to find the process ID to stop it:
$ ps auxww | grep datapipe root 21570 0.0 0.1 44 132 ?? Is 8:45PM 0:00.00 ./datapipe
my.host 9080 80 ...
$ kill -9 21570
1) FPipe
FPipe, from McAfee, implements port redirection techniques natively in Windows. It also adds
User Datagram Protocol (UDP) support, which Datapipe lacks FPipe does not require any
support DLLs or privileged user access. It runs on all Windows platforms. The lack of support
DLLs or similar files makes it easy to pick up fpipe.exe and drop it onto a system. FPipe also
adds more capability than Datapipe in its ability to use a source port and bind to a specific
interface.
Implementation
Here’s FPipe’s equivalent, with connection logs as new clients access the listening port:
WinRelay is another Windows-based port redirection tool. It and FPipe share the same features,
including the ability to define a static source port for redirected traffic.
Consequently, it can be used interchangeably with FPipe on any Windows platform
Usage: winrelay -lip <IP/DNS address> -lp <port> [-sip <IP/DNS address>]
[-sp <port>] -dip <IP/DNS address> -dp <port> -proto <protocol>
-lip = IP (v4/v6) or DNS address to listen at
(to listen on all addresses on all interfaces use
-lip allv4 or -lip allv6)
-lp = port to listen at
-sip = source IP (v4/v6) or DNS address for connection to destination
-sp = source port for connection to destination
-dip = destination IP (v4/v6) or DNS address
-dp = destination port
-proto = protocol ("tcp" or "udp")
1) Netcat
Netcat performs a narrow function with a broad application to hacking and network debugging:
it reads and writes data for TCP and UDP connections. Just like the command redirection
concepts, Netcat enables you to redirect shell commands across a network. It’s a cat command
for networking, with capabilities limited only by imagination..Netcat interacts directly with a
TCP or UDP service. You can inspect the raw data sent by a service, manually interact with the
service, or redirect network connections with stdin, stdout, or stderr.
. nc
Command Options
The basic command line for Netcat is nc [options] host ports, where host is the hostname or
IP address to connect to and ports is either a single port, a port range (specified “m-n”), or
individual ports separated by spaces, depending on the desired behavior.
Take an in-depth look at the most useful of the command-line options:
• -e command If Netcat was compiled with the GAPING_SECURITY_HOLE option,
this option causes a listening Netcat to execute command any time someone makes a
connection on the port to which it is listening, while a client Netcat will pipe the I/O to an
instance of Netcat listening elsewhere.
• -g and -G Affect loose source routing used to attempt to hide or spoof the source of
traffic.
• -i seconds Specifies the delay interval that Netcat waits between sending data.
• -l Toggles Netcat’s “listen” mode. This binds Netcat to a local port to await incoming
TCP connections, making it act as a server. For the original Netcat, the local port is specified
with the -p option (e.g., nc -l -p 8000). For modern Netcat clones, omit the -p option; they
expect to use the value from the port section of the command line (e.g., nc -l 8000). Combine
this with -u to listen for incoming UDP connections instead of TCP.
• -n Tells Netcat to forego hostname lookups. If you use this option, you must
specify an IP address instead of a hostname.
• -o file Dumps communications over this channel to the specified file. The output is
written in hexadecimal format. This option records data going in both directions and begins
each line with < or > to indicate incoming or outgoing data, respectively.
• -p port Lets you specify the local port number Netcat should use, also referred to as
the source port of a connection. For the original Netcat, this argument is required when using
the –l or –L option to start listen mode.
• -r Chooses random local and remote port numbers.
• -s Specifies the source IP address Netcat should use when making its connections.
This option allows hackers to do some pretty sneaky tricks, if it works.
• -t Enables Netcat, if compiled with the TELNET option, to handle telnet option
negotiation with a telnet server, responding with meaningless information but allowing you to
get to that login prompt you were probably looking for when using Netcat to connect to TCP
port 23.
• -u Tells Netcat to bind to a UDP port instead of a TCP port. Works for both client
and listen mode. UDP mode isn’t reliable for port scanning (most UDP services require incoming
data to elicit a response that indicates the port is open and a service is listening), but it works well
enough for simple packet communication when TCP won’t work. Some tricks for making UDP
scans more reliable are provided later in this chapter.
• -v Controls how much Netcat tells you about what it’s doing. Without –v, Netcat
only reports the data it receives. A single –v will let you know what address it’s connecting or
binding to and if any problems occur.
• -w seconds Controls how long Netcat waits before giving up on a connection. It also
tells the command how long to wait after an EOF (end-of-file) is received on standard input before
closing the connection and exiting.
• -z Tells Netcat to send only enough data to discover which ports in your specified
range actually have something listening on them. In other words, it just tries to connect, then
immediately disconnects if successful. It won’t keep the connection open. If you care only about
finding out which ports are open, you should probably be using Nmap
2) Socat
Socat is a Netcat clone with extensive configuration options. It supports several protocols, from
OpenSSL to proxies to IPv4 and IPv6. Its home page is at www.dest-unreach.org/ socat/.
The biggest difference you’ll notice from other clones is socat’s departure from familiar
command-line options. Instead of the alphabet soup of Netcat’s flags, socat uses word-based
directives on the command line. Socat is part of the BSD ports collection and available as a
package for most Linux distributions.
Implementation
Socat’s command line follows a simple format, as follows:
The options resemble common “dash letter” flags such as -d, -h, and -v. These do not match the
options of other Netcat clones; they mostly work to toggle the level of debugging and type of
logging generated by socat.
The address specifications represent the most powerful, but perhaps the most confusing at first,
aspect of socat. A basic address specification consists of a keyword, followed by a list of parameters
and behavior options. Address specifications are not case sensitive, but we’ll define them in
uppercase to help distinguish them on the command line. For example, the following command
connects stdio (the first address) to TCP port 80 on a remote host (the second address):
Since the first address is stdio, you can pipe data into the command just as you would with nc or
any other shell command. Traffic is forwarded between the two addresses. Hence, the data piped
into stdio is forwarded to the TCP host, whose response makes the round trip back through stdio.
1) Tcpdump
The tcpdump command is present by default on most Unix-based systems. It’s long been a
part of the Unix lineage due to its usefulness in debugging networks and services. However,
its potential for abuse, especially in the era of remote administration via telnet, gave tcpdump
a bad reputation. If it’s not installed by default, check your system’s package management
software.
2) WinDump
WinDump is the tcpdump command’s counterpart for Windows systems. Its home page,
http://winpcap.org, contains installers. Note that the windump command relies on the WinPcap
driver for packet captures.
Implementation
Tcpdump and WinDump both use the packet capture (pcap) library, a set of packet capture
routines written by the Lawrence Berkeley National Laboratory. The pcap routines provide the
interface and functionality for OS-level packet filtering and disassembling IP packets into raw
data.Because WinDump is simply a Windows port of tcpdump, the two commands are mostly
interchangeable throughout this chapter. We will focus on tcpdump, noting any differences with
WinDump along the way. Most of the time, the only difference is the name of the network
interface to specify for capturing traffic.