0% found this document useful (0 votes)
20 views21 pages

Imp Mad Programs

Uploaded by

ahireaditya79
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)
20 views21 pages

Imp Mad Programs

Uploaded by

ahireaditya79
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/ 21

1. Develop a program to implement list view of 5 items.

XML

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

<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android

Android:orientation=”vertical”

Android:layout_width=”match_parent”

Android:layout_height=”match_parent”>

<ListView

Android:id=”@+id/listView”

Android:layout_width=”match_parent”

Android:layout_height=”wrap_content” />

</LinearLayout>

Java

Package com.example.listviewdemo;

Import android.app.Activity;

Import android.os.Bundle;

Import android.widget.ArrayAdapter;

Import android.widget.ListView;

Public class MainActivity extends Activity {

@Override

Protected void onCreate(Bundle savedInstanceState) {

Super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

// Sample data for the ListView

String[] items = {“Item 1”, “Item 2”, “Item 3”, “Item 4”, “Item 5”};

// Getting reference to the ListView

ListView listView = findViewById(R.id.listView);


// Creating adapter to bind data to the ListView

ArrayAdapter<String> adapter = new ArrayAdapter<>(this,

Android.R.layout.simple_list_item_1, items);

// Setting the adapter to the ListView

listView.setAdapter(adapter);

Manifest

<application

…>

<activity android:name=”.MainActivity”>

<intent-filter>

<action android:name=”android.intent.action.MAIN” />

<category android:name=”android.intent.category.LAUNCHER” />

</intent-filter>

</activity>

</application>

2. Grid view of 4 × 4 items

XML

<GridView xmlns:android=http://schemas.android.com/apk/res/android

Android:id=”@+id/gridView”

Android:layout_width=”match_parent”

Android:layout_height=”match_parent”

Android:numColumns=”4” />

Java

Packagecom.example.gridviewdemo;

Import android.app.Activity;
Import android.os.Bundle;

Import android.widget.ArrayAdapter;

Import android.widget.GridView;

Public class MainActivity extends Activity {

@Override

Protected void onCreate(Bundle savedInstanceState) {

Super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

// Prepare 16 items

String[] items = new String[16];

For (int i = 0; i < 16; i++) {

Items[i] = “Item “ + (i + 1);

// Setup GridView and Adapter

GridView gridView = findViewById(R.id.gridView);

ArrayAdapter<String> adapter = new ArrayAdapter<>(this,

Android.R.layout.simple_list_item_1, items);

gridView.setAdapter(adapter);

3. Image view

XML

<ImageView xmlns:android=http://schemas.android.com/apk/res/android

Android:id=”@+id/imageView”

Android:layout_width=”wrap_content”

Android:layout_height=”wrap_content”
Android:src=”@drawable/sample_image” />

Java

Public class MainActivity extends Activity {

Protected void onCreate(Bundle savedInstanceState) {

Super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

ImageView img = findViewById(R.id.imageView);

Img.setImageResource(R.drawable.sample_image);

4. Design UI using table layout to display buttons with 09 numbers on it. Even display
Submit and clear button. When user clicks on particular buttons and later when clicks on
submit button, it should display the numbers clicked. (Note: Consider the appropriate
XML file. All attributes are not required. In java file all imports are not expected. Different
relevant logic/code can be considered.)

XML

<TableLayout xmlns:android=http://schemas.android.com/apk/res/android
Android:layout_width=”match_parent” android:layout_height=”match_parent”
Android:stretchColumns=”*”>

<TableRow>
<Button android:id=”@+id/b1” android:text=”1”/>
<Button android:id=”@+id/b2” android:text=”2”/>
<Button android:id=”@+id/b3” android:text=”3”/>
</TableRow>
<TableRow>
<Button android:id=”@+id/b4” android:text=”4”/>
<Button android:id=”@+id/b5” android:text=”5”/>
<Button android:id=”@+id/b6” android:text=”6”/>
</TableRow>
<TableRow>
<Button android:id=”@+id/b7” android:text=”7”/>
<Button android:id=”@+id/b8” android:text=”8”/>
<Button android:id=”@+id/b9” android:text=”9”/>
</TableRow>
<TableRow>
<Button android:id=”@+id/b0” android:text=”0”/>
<Button android:id=”@+id/submit” android:text=”Submit”/>
<Button android:id=”@+id/clear” android:text=”Clear”/>
</TableRow>
<TextView android:id=”@+id/output” android:text=”” />
</TableLayout>

Java

Public class MainActivity extends Activity {

StringBuilder input = new StringBuilder();

Protected void onCreate(Bundle b) {

Super.onCreate(b);

setContentView(R.layout.activity_main);

TextView out = findViewById(R.id.output);

View.OnClickListener numClick = v → {

Button btn = (Button)v;

Input.append(btn.getText());

};

Int[] ids = {R.id.b0,R.id.b1,R.id.b2,R.id.b3,R.id.b4,

R.id.b5,R.id.b6,R.id.b7,R.id.b8,R.id.b9};

For(int id : ids)

findViewById(id).setOnClickListener(numClick);

findViewById(R.id.submit).setOnClickListener(v → out.setText(“You clicked: “ + input));

findViewById(R.id.clear).setOnClickListener(v → {

input.setLength(0);

out.setText(“”);

});
}

5. Program to Turn ON , Turn OFF , show list of paired devices of bluetooth

XML

<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
Android:orientation=”vertical” android:layout_width=”match_parent”
Android:layout_height=”match_parent” android:padding=”16dp”>

<Button android:id=”@+id/on” android:text=”Turn ON”/>


<Button android:id=”@+id/off” android:text=”Turn OFF”/>
<Button android:id=”@+id/paired” android:text=”Paired Devices”/>
<TextView android:id=”@+id/list” android:text=””/>
</LinearLayout>

Java

Public class MainActivity extends Activity {


BluetoothAdapter bAdapter;
TextView list;

Protected void onCreate(Bundle b) {


Super.onCreate(b);
setContentView(R.layout.activity_main);

bAdapter = BluetoothAdapter.getDefaultAdapter();
list = findViewById(R.id.list);

findViewById(R.id.on).setOnClickListener(v → {
if (!bAdapter.isEnabled())
bAdapter.enable();
});

findViewById(R.id.off).setOnClickListener(v → {
if (bAdapter.isEnabled())
bAdapter.disable();
});

findViewById(R.id.paired).setOnClickListener(v → {
Set<BluetoothDevice> paired = bAdapter.getBondedDevices();
StringBuilder sb = new StringBuilder(“Paired Devices:\n”);
For (BluetoothDevice d : paired)
Sb.append(d.getName()).append(“\n”);
List.setText(sb.toString());
});
}
}

*Permission*
<uses-permission android:name=”android.permission.BLUETOOTH”/>
<uses-permission android:name=”android.permission.BLUETOOTH_ADMIN”/>

6. Write a program to capture an image using camera and display it.

Xml

<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
Android:layout_width=”match_parent” android:layout_height=”match_parent”
Android:orientation=”vertical” android:padding=”16dp”>

<Button android:id=”@+id/captureBtn” android:text=”Capture Image” />


<ImageView android:id=”@+id/imageView”
Android:layout_width=”match_parent”
Android:layout_height=”300dp” />
</LinearLayout>

Manifest

<uses-permission android:name=”android.permission.CAMERA”/>
<uses-feature android:name=”android.hardware.camera” android:required=”true”/>

Java

Package com.example.captureimage;

Import android.content.Intent;
Import android.graphics.Bitmap;
Import android.os.Bundle;
Import android.provider.MediaStore;
Import android.widget.Button;
Import android.widget.ImageView;
Import androidx.appcompat.app.AppCompatActivity;

Public class MainActivity extends AppCompatActivity {

Static final int REQUEST_IMAGE = 1;


ImageView img;

@Override
Protected void onCreate(Bundle savedInstanceState) {
Super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

img = findViewById(R.id.imageView);
Button btn = findViewById(R.id.captureBtn);

Btn.setOnClickListener(v → {
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, REQUEST_IMAGE);
});
}

@Override
Protected void onActivityResult(int reqCode, int resCode, Intent data) {
Super.onActivityResult(reqCode, resCode, data);
If (reqCode == REQUEST_IMAGE && resCode == RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get(“data”);
Img.setImageBitmap(photo);
}
}
}

7. Text to speech conversation program

Xml

<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
Android:layout_width=”match_parent” android:layout_height=”match_parent”
Android:orientation=”vertical” android:padding=”16dp”>

<EditText android:id=”@+id/inputText”
Android:layout_width=”match_parent”
Android:layout_height=”wrap_content”
Android:hint=”Enter text here” />

<Button android:id=”@+id/speakBtn”
Android:layout_width=”wrap_content”
Android:layout_height=”wrap_content”
Android:text=”Speak” />
</LinearLayout>

Java

Package com.example.texttospeech;
Import android.os.Bundle;
Import android.speech.tts.TextToSpeech;
Import android.widget.Button;
Import android.widget.EditText;
Import androidx.appcompat.app.AppCompatActivity;
Import java.util.Locale;

Public class MainActivity extends AppCompatActivity {

TextToSpeech tts;

@Override
Protected void onCreate(Bundle savedInstanceState) {
Super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

EditText input = findViewById(R.id.inputText);


Button speak = findViewById(R.id.speakBtn);

Tts = new TextToSpeech(this, status → {


If (status == TextToSpeech.SUCCESS) {
Tts.setLanguage(Locale.US);
}
});

Speak.setOnClickListener(v → {
String text = input.getText().toString();
Tts.speak(text, TextToSpeech.QUEUE_FLUSH, null, null);
});
}

@Override
Protected void onDestroy() {
If (tts != null) {
Tts.stop();
Tts.shutdown();
}
Super.onDestroy();
}
}

8. Getting current location of user.

XML

<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
Android:layout_width=”match_parent” android:layout_height=”match_parent”
Android:orientation=”vertical” android:padding=”16dp”>

<Button android:id=”@+id/getLocBtn” android:text=”Get Location” />


<TextView android:id=”@+id/locationText” android:text=”Location: “ />
</LinearLayout>

Java

Package com.example.getlocation;

Import android.Manifest;
Import android.content.pm.PackageManager;
Import android.location.Location;
Import android.os.Bundle;
Import android.widget.Button;
Import android.widget.TextView;
Import androidx.annotation.NonNull;
Import androidx.appcompat.app.AppCompatActivity;
Import androidx.core.app.ActivityCompat;
Import com.google.android.gms.location.*;

Public class MainActivity extends AppCompatActivity {

FusedLocationProviderClient locationClient;
TextView locationText;

@Override
Protected void onCreate(Bundle b) {
Super.onCreate(b);
setContentView(R.layout.activity_main);

locationText = findViewById(R.id.locationText);
Button getLocBtn = findViewById(R.id.getLocBtn);
locationClient = LocationServices.getFusedLocationProviderClient(this);

getLocBtn.setOnClickListener(v → {
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new
String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
Return;
}

locationClient.getLastLocation().addOnSuccessListener(this, location → {
if (location != null) {
double lat = location.getLatitude();
double lon = location.getLongitude();
locationText.setText(“Location: “ + lat + “, “ + lon);
} else {
locationText.setText(“Location not available”);
}
});
});
}

@Override
Public void onRequestPermissionsResult(int req, @NonNull String[] perms, @NonNull int[]
grantResults) {
If (req == 1 && grantResults.length > 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
Recreate(); // retry getting location after permission
}
}
}

Manifest permission

<uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION”/>

Gradle

Implementation ‘com.google.android.gms:play-services-location:21.0.1’

9. Explain explicit intent with example

XMl

<Button android:id=”@+id/btnNext”
Android:layout_width=”wrap_content”
Android:layout_height=”wrap_content”
Android:text=”Go to Second”/>

Main activity 1

Public class MainActivity extends AppCompatActivity {


Protected void onCreate(Bundle b) {
Super.onCreate(b);
setContentView(R.layout.activity_main);

Button btn = findViewById(R.id.btnNext);


Btn.setOnClickListener(v → {
Intent i = new Intent(MainActivity.this, SecondActivity.class);
startActivity(i); // Explicit Intent
});
}
}

Main activity 2

Public class SecondActivity extends AppCompatActivity {


Protected void onCreate(Bundle b) {
Super.onCreate(b);
setContentView(R.layout.activity_second);
}
}

Manifest

<activity android:name=”.SecondActivity” />

10. Google map

Xml

<fragment xmlns:android=http://schemas.android.com/apk/res/android
Android:id=”@+id/map”
Android:name=”com.google.android.gms.maps.SupportMapFragment”
Android:layout_width=”match_parent”
Android:layout_height=”match_parent”/>

Java

Public class MainActivity extends FragmentActivity implements OnMapReadyCallback {


GoogleMap map;

Protected void onCreate(Bundle b) {


Super.onCreate(b);
setContentView(R.layout.activity_main);

SupportMapFragment smf = (SupportMapFragment) getSupportFragmentManager()


.findFragmentById(R.id.map);
Smf.getMapAsync(this);
}

Public void onMapReady(GoogleMap gMap) {


Map = gMap;
Map.setMyLocationEnabled(true);
}
}

Manifest

<uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION”/>
<uses-permission android:name=”android.permission.INTERNET”/>

Google map api keys

<meta-data
Android:name=”com.google.android.geo.API_KEY”
Android:value=”YOUR_API_KEY”/>

11. Find direction from user current location to MSBTE, Bandra.


XMl
<?xml version=”1.0” encoding=”utf-8”?>
<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
Android:layout_width=”match_parent”
Android:layout_height=”match_parent”
Android:gravity=”center”
Android:orientation=”vertical”>

<Button
Android:id=”@+id/btnDirections”
Android:layout_width=”wrap_content”
Android:layout_height=”wrap_content”
Android:text=”Get Directions to MSBTE” />
</LinearLayout>

Java
Package com.example.directionsapp;

Import android.content.Intent;
Import android.net.Uri;
Import android.os.Bundle;
Import android.view.View;
Import android.widget.Button;
Import androidx.appcompat.app.AppCompatActivity;

Public class MainActivity extends AppCompatActivity {


Button btnDirections;
@Override
Protected void onCreate(Bundle savedInstanceState) {
Super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnDirections = findViewById(R.id.btnDirections);

btnDirections.setOnClickListener(new View.OnClickListener() {
@Override
Public void onClick(View view) {
// Directions from current location to MSBTE, Bandra
Uri uri = Uri.parse(“google.navigation:q=MSBTE+Bandra”);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
Intent.setPackage(“com.google.android.apps.maps”);
startActivity(intent);
}
});
}
}
Manifest
<uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION” />
<uses-permission android:name=”android.permission.INTERNET” />

12. Develop an android application for taking student feedback with database connectivity.
XML
<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
Android:layout_width=”match_parent”
Android:layout_height=”match_parent”
Android:orientation=”vertical”
Android:padding=”20dp”>

<EditText
Android:id=”@+id/name”
Android:hint=”Name”
Android:layout_width=”match_parent”
Android:layout_height=”wrap_content”/>

<EditText
Android:id=”@+id/feedback”
Android:hint=”Feedback”
Android:layout_width=”match_parent”
Android:layout_height=”wrap_content”/>

<Button
Android:id=”@+id/save”
Android:text=”Save”
Android:layout_width=”match_parent”
Android:layout_height=”wrap_content”/>
</LinearLayout>

Java
Package com.example.feedbackapp;

Import android.os.Bundle;
Import android.view.View;
Import android.widget.*;
Import androidx.appcompat.app.AppCompatActivity;

Public class MainActivity extends AppCompatActivity {


EditText name, feedback;
Button save;
MyDB db;

@Override
Protected void onCreate(Bundle b) {
Super.onCreate(b);
setContentView(R.layout.activity_main);

name = findViewById(R.id.name);
feedback = findViewById(R.id.feedback);
save = findViewById(R.id.save);
db = new MyDB(this);

save.setOnClickListener(v → {
db.saveData(name.getText().toString(), feedback.getText().toString());
Toast.makeText(this, “Saved”, Toast.LENGTH_SHORT).show();
});
}
}

Database.java
Package com.example.feedbackapp;

Import android.content.*;
Import android.database.sqlite.*;

Public class MyDB extends SQLiteOpenHelper {


Public MyDB(Context c) {
Super(c, “fbDB”, null, 1);
}
Public void onCreate(SQLiteDatabase db) {
Db.execSQL(“CREATE TABLE fb(name TEXT, feedback TEXT)”);
}

Public void onUpgrade(SQLiteDatabase db, int oldV, int newV) {}

Public void saveData(String n, String f) {


SQLiteDatabase db = this.getWritableDatabase();
Db.execSQL(“INSERT INTO fb VALUES(‘” + n + “’, ‘” + f + “’)”);
}
}

13. Program to create simple Database in Android


Db.java
Package com.example.simpledb;
Import android.content.Context;
Import android.database.sqlite.SQLiteDatabase;
Import android.database.sqlite.SQLiteOpenHelper;
Public class MyDB extends SQLiteOpenHelper {
Public MyDB(Context c) {
Super(c, “myDB”, null, 1); // “myDB” is the database name
}
@Override
Public void onCreate(SQLiteDatabase db) {
Db.execSQL(“CREATE TABLE student(id INTEGER PRIMARY KEY, name TEXT)”);
}
@Override
Public void onUpgrade(SQLiteDatabase db, int oldV, int newV) {
Db.execSQL(“DROP TABLE IF EXISTS student”);
onCreate(db);
}
}

MainActivity.java
Package com.example.simpledb;

Import android.os.Bundle;
Import androidx.appcompat.app.AppCompatActivity;

Public class MainActivity extends AppCompatActivity {


@Override
Protected void onCreate(Bundle b) {
Super.onCreate(b);
setContentView(R.layout.activity_main);
MyDB db = new MyDB(this); // Database is created here
}
}

14. Send and recieve SMS


Xml
<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
Android:layout_width=”match_parent”
Android:layout_height=”match_parent”
Android:orientation=”vertical”
Android:padding=”16dp”>

<EditText android:id=”@+id/number” android:hint=”Phone Number”


Android:layout_width=”match_parent” android:layout_height=”wrap_content”/>

<EditText android:id=”@+id/message” android:hint=”Message”


Android:layout_width=”match_parent” android:layout_height=”wrap_content”/>

<Button android:id=”@+id/send” android:text=”Send SMS”


Android:layout_width=”match_parent” android:layout_height=”wrap_content”/>
</LinearLayout>

MainAct.java
Package com.example.smsdemo;

Import android.os.Bundle;
Import android.telephony.SmsManager;
Import android.widget.*;
Import androidx.appcompat.app.AppCompatActivity;

Public class MainActivity extends AppCompatActivity {


EditText number, message;
Button send;

@Override
Protected void onCreate(Bundle b) {
Super.onCreate(b);
setContentView(R.layout.activity_main);

number = findViewById(R.id.number);
message = findViewById(R.id.message);
send = findViewById(R.id.send);

send.setOnClickListener(v → {
SmsManager sms = SmsManager.getDefault();
Sms.sendTextMessage(number.getText().toString(), null, message.getText().toString(),
null, null);
Toast.makeText(this, “SMS Sent”, Toast.LENGTH_SHORT).show();
});
}
}

Smsreceiver.java
Package com.example.smsdemo;

Import android.content.*;
Import android.os.Bundle;
Import android.telephony.SmsMessage;
Import android.widget.Toast;

Public class SMSReceiver extends BroadcastReceiver {


Public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
If (bundle != null) {
Object[] pdus = (Object[]) bundle.get(“pdus”);
For (Object p : pdus) {
SmsMessage sms = SmsMessage.createFromPdu((byte[]) p);
String msg = sms.getMessageBody();
Toast.makeText(context, “Received: “ + msg, Toast.LENGTH_LONG).show();
}
}
}
}

15. Program to display list of sensors


Xml
<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
Android:layout_width=”match_parent”
Android:layout_height=”match_parent”
Android:orientation=”vertical”>

<ListView
Android:id=”@+id/list”
Android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>

MainAct.java
Package com.example.sensorlist;
Import android.hardware.Sensor;
Import android.hardware.SensorManager;
Import android.os.Bundle;
Import android.widget.ArrayAdapter;
Import android.widget.ListView;
Import androidx.appcompat.app.AppCompatActivity;
Import java.util.*;

Public class MainActivity extends AppCompatActivity {


ListView listView;

@Override
Protected void onCreate(Bundle b) {
Super.onCreate(b);
setContentView(R.layout.activity_main);
listView = findViewById(R.id.list);

SensorManager sm = (SensorManager) getSystemService(SENSOR_SERVICE);


List<Sensor> sensors = sm.getSensorList(Sensor.TYPE_ALL);

List<String> names = new ArrayList<>();


For (Sensor s : sensors)
Names.add(s.getName());

listView.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1,


names));
}
}

16. Write a program to send an email


Xml
<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
Android:layout_width=”match_parent”
Android:layout_height=”match_parent”
Android:orientation=”vertical”
Android:padding=”20dp”>

<EditText
Android:id=”@+id/email”
Android:hint=”Email Address”
Android:layout_width=”match_parent”
Android:layout_height=”wrap_content”/>

<EditText
Android:id=”@+id/subject”
Android:hint=”Subject”
Android:layout_width=”match_parent”
Android:layout_height=”wrap_content”/>

<EditText
Android:id=”@+id/body”
Android:hint=”Message”
Android:layout_width=”match_parent”
Android:layout_height=”wrap_content”/>

<Button
Android:id=”@+id/send”
Android:text=”Send Email”
Android:layout_width=”match_parent”
Android:layout_height=”wrap_content”/>
</LinearLayout>

MainAct.java
Package com.example.sendemail;

Import android.content.Intent;
Import android.net.Uri;
Import android.os.Bundle;
Import android.widget.*;
Import androidx.appcompat.app.AppCompatActivity;

Public class MainActivity extends AppCompatActivity {


EditText email, subject, body;
Button send;

@Override
Protected void onCreate(Bundle b) {
Super.onCreate(b);
setContentView(R.layout.activity_main);

email = findViewById(R.id.email);
subject = findViewById(R.id.subject);
body = findViewById(R.id.body);
send = findViewById(R.id.send);

send.setOnClickListener(v → {
Intent i = new Intent(Intent.ACTION_SENDTO);
i.setData(Uri.parse(mailto: + email.getText().toString()));
i.putExtra(Intent.EXTRA_SUBJECT, subject.getText().toString());
i.putExtra(Intent.EXTRA_TEXT, body.getText().toString());
startActivity(i);
});
}
}

You might also like