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

Android imp

The document outlines the development of four Android applications: one for sending and receiving emails using Intent, another for providing Bluetooth connectivity using BluetoothAdapter, a third for accessing Google Maps location with appropriate permissions, and a fourth for capturing images using the camera through ACTION_IMAGE_CAPTURE Intent. Each application includes steps for creating a new project, working with XML layout files, and implementing functionality in the MainActivity file. The document provides code snippets and explanations for each application's components and methods.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Android imp

The document outlines the development of four Android applications: one for sending and receiving emails using Intent, another for providing Bluetooth connectivity using BluetoothAdapter, a third for accessing Google Maps location with appropriate permissions, and a fourth for capturing images using the camera through ACTION_IMAGE_CAPTURE Intent. Each application includes steps for creating a new project, working with XML layout files, and implementing functionality in the MainActivity file. The document provides code snippets and explanations for each application's components and methods.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

1.

Develope a program to send and receive mail


Ans-
Android Application that can be used to send email through your android application.
You can do so with the help of Intent with action as ACTION_SEND with extra fields:
● email id to which you want to send mail,

● the subject of the email and

● body of the email.

Basically Intent is a simple message object that is used to communicate between android

components such as activities, content providers, broadcast receivers, and services, here use

to send the email. This application basically contains one activity with EditText to take input of

email address, subject, and body of the email from the user and button to send that email.

Step 1: Create a New Project in Android Studio

Step 2: Working with the XML Files

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


<!-- Relative Layout -->
<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">

<!-- Edit text for email id -->


<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="18dp"
android:layout_marginRight="22dp" />
<!-- Edit text for email subject -->
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_alignLeft="@+id/editText1"
android:layout_marginTop="20dp" />

<!-- Edit text for email body -->


<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_alignLeft="@+id/editText2"
android:layout_marginTop="30dp" />

<!-- text Views for label -->


<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText1"
android:layout_alignBottom="@+id/editText1"
android:layout_alignParentLeft="true"
android:text="Send To:"
android:textColor="#0F9D58" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText2"
android:layout_alignBottom="@+id/editText2"
android:layout_alignParentLeft="true"
android:text="Email Subject:"
android:textColor="#0F9D58" />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText3"
android:layout_alignBottom="@+id/editText3"
android:text="Email Body:"
android:textColor="#0F9D58" />

<!-- Button to send email -->


<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText3"
android:layout_alignLeft="@+id/editText3"
android:layout_marginLeft="76dp"
android:layout_marginTop="20dp"
android:text="Send email!!" />
</RelativeLayout>

step 3: Working with the MainActivity File

In MainActivity Intent object is created and its action is defined to ACTION_SEND to send an
email, with Intent three extra fields are also added using the putExtra function. These fields
are: Email of receiver

● Subject of email

● Body of email
2. Develope a program for providing Bluetooth connectivity.
Ans-
Android provides Bluetooth API to perform these different operations.

​ Scan for other Bluetooth devices


​ Get a list of paired devices
​ Connect to other devices through service discovery

Android provides BluetoothAdapter class to communicate with Bluetooth. Create an


object of this calling by calling the static method getDefaultAdapter(). Its syntax is
given below.

private BluetoothAdapter BA;


BA = BluetoothAdapter.getDefaultAdapter();

In order to enable the Bluetooth of your device, call the intent with the following
Bluetooth constant ACTION_REQUEST_ENABLE. Its syntax is.

Intent turnOn = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);


startActivityForResult(turnOn, 0);
Methods:

Once you enable the Bluetooth , you can get a list of paired devices by calling
getBondedDevices() method. It returns a set of bluetooth devices. Its syntax is.

private Set<BluetoothDevice>pairedDevices;
pairedDevices = BA.getBondedDevices();
3. program on Google Map location

Add the permissions to the app manifest


If approximate location is only needed for your app to function, then add the
ACCESS_COARSE_LOCATION permission to your app's manifest file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp" >
...
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION"/>
...
</manifest>
However, if precise location is needed, then add both ACCESS_COARSE_LOCATION
and ACCESS_FINE_LOCATION permissions to your app's manifest file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp" >
...
<uses-permissionandroid:name="android.permission.ACCESS_COARSE_LOCATION"/
>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
...
</manifest>

4. WAP to capture an image using camera


Ans-
The opening of the Camera from inside our app is achieved with the help of
the ACTION_IMAGE_CAPTURE Intent of MediaStore class.

Step 1: Create a New Project in Android Studio

Step 2: Working with the XML Files

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

<!-- add Camera Button to open the Camera -->


<Button
android:id="@+id/camera_button"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_marginStart="150dp"
android:text="Camera" />

<!-- add ImageView to display the captured image -->


<ImageView
android:id="@+id/click_image"
android:layout_width="350dp"
android:layout_height="450dp"
android:layout_marginStart="30dp"
android:layout_marginTop="70dp"
android:layout_marginBottom="10dp" />
</RelativeLayout>

Step 3: Working with the MainActivity File

You might also like