PROGRAM TO GET USER’S CURRENT LOCATION
package [Link];
import [Link];import [Link];import
[Link];import [Link];import
[Link];import
[Link];import [Link];
import [Link];
public class MainActivity extends Activity implements
LocationListener{protected LocationManager locationManager;protected
LocationListener locationListener;protected Context context;TextView
txtLat;String lat;String provider;protected String latitude,longitude;
protected boolean gps_enabled,network_enabled;
@Overrideprotected void onCreate(Bundle savedInstanceState)
{[Link](savedInstanceState);
setContentView([Link].activity_main);
txtLat = (TextView) findViewById([Link].textview1);
locationManager = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
[Link](LocationManager.GPS_PROVIDER,
0, 0, this);}@Overridepublic void onLocationChanged(Location location)
{
txtLat = (TextView) findViewById([Link].textview1);
[Link]("Latitude:" + [Link]() + ", Longitude:"
+ [Link]());}
@Overridepublic void onProviderDisabled(String provider)
{Log.d("Latitude","disable");}
@Overridepublic void onProviderEnabled(String provider)
{Log.d("Latitude","enable");}
@Overridepublic void onStatusChanged(String provider, int status,
Bundle extras) {Log.d("Latitude","status");}}
XML files for layout
<RelativeLayout
xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world" />
</RelativeLayout>
PROGRAM FOR PROGRESSBAR
<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<ProgressBar
android:id="@+id/simpleProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:layout_centerHorizontal="true"/>
<Button
android:id="@+id/startButton"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="Start"
android:textSize="20sp"
android:textStyle="bold"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"
android:padding="10dp"
android:background="#0f0"
android:textColor="#fff"/>
</RelativeLayout>
.JAVA FILE
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
// initiate progress bar and start button
final ProgressBar simpleProgressBar = (ProgressBar) findViewById([Link]);
Button startButton = (Button) findViewById([Link]);
// perform click event on button
[Link](new [Link]() {
@Override
public void onClick(View v) {
// visible the progress bar
[Link]([Link]);
}
});
}
PROGRAM FOR SCROLLVIEW
<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="20dp"
android:orientation="vertical">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#f00"
android:text="Button 1"
android:textColor="#fff"
android:textSize="20sp" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#0f0"
android:text="Button 2"
android:textColor="#fff"
android:textSize="20sp" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#00f"
android:text="Button 3"
android:textColor="#fff"
android:textSize="20sp" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#ff0"
android:text="Button 4"
android:textColor="#fff"
android:textSize="20sp" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#f0f"
android:text="Button 5"
android:textColor="#fff"
android:textSize="20sp" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#f90"
android:text="Button 6"
android:textColor="#fff"
android:textSize="20sp" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#f00"
android:text="Button 7"
android:textColor="#ff9"
android:textSize="20sp" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#444"
android:text="Button 8"
android:textColor="#fff"
android:textSize="20sp" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#ff002211"
android:text="Button 9"
android:textColor="#fff"
android:textSize="20sp" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#0f0"
android:text="Button 10"
android:textColor="#fff"
android:textSize="20sp" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
.JAVA FILE
package [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
}
PROGRAM TO RECEIVE SMS
package [Link];
import [Link];import
[Link];import [Link];import
[Link];import [Link];import
[Link];
public class SmsBroadcastReceiver extends BroadcastReceiver {
public static final String SMS_BUNDLE = "pdus";
public void onReceive(Context context, Intent intent) {
Bundle intentExtras = [Link]();
if (intentExtras != null) {
Object[] sms = (Object[]) [Link](SMS_BUNDLE);
String smsMessageStr = "";
for (int i = 0; i < [Link]; ++i) {
SmsMessage smsMessage =
[Link]((byte[]) sms[i]);
String smsBody =
[Link]().toString();
String address = [Link]();
smsMessageStr += "SMS From: " + address + "\n";
smsMessageStr += smsBody + "\n";
[Link](context, smsMessageStr,
Toast.LENGTH_SHORT).show();
//this will update the UI with message
SmsActivity inst = [Link]();
[Link](smsMessageStr);
}}
<?xml version="1.0" encoding="utf-8"?><LinearLayout
xmlns:android="[Link]
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/MainLayout"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="SMS Inbox"
android:id="@+id/textView"
android:layout_gravity="center_horizontal" />
</LinearLayout>
Write a program to find the direction from user's current location
to MSBTE, Bandra.
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MapsActivity extends AppCompatActivity implements OnMapReadyCallback {
private GoogleMap mMap;
private FusedLocationProviderClient fusedLocationClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_maps);
fusedLocationClient = [Link](this);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById([Link]);
[Link](this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
getCurrentLocation();
}
private void getCurrentLocation() {
if ([Link](this, [Link].ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
[Link](this, new
String[]{[Link].ACCESS_FINE_LOCATION}, 1);
return;
}
[Link]().addOnSuccessListener(this, location -> {
if (location != null) {
LatLng userLocation = new LatLng([Link](), [Link]());
[Link](new MarkerOptions().position(userLocation).title("You are here"));
[Link]([Link](userLocation, 15));
getDirections(userLocation);
}
});
}
private void getDirections(LatLng userLocation) {
LatLng msbteLocation = new LatLng(19.0728, 72.8347); // MSBTE, Bandra coordinates
// Call Google Directions API here to get the route
// Display the route on the map
}
}
.xml
<fragment
xmlns:android="[Link]
android:id="@+id/map"
android:name="[Link]"
android:layout_width="match_parent"
android:layout_height="match_parent"/>