Mad 5-1
Mad 5-1
Mad 5-1
MainActivity.java
package com.example.pa;
import android.content.Intent;
import android.os.Bundle;
import android.provider.MediaStore;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.cameraButton).setOnClickListener(view ->
{
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK)
{ } }}
Activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/cameraButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Take Photo" />
</RelativeLayout>
Bluetooth
MainActivity.java
import android.bluetooth.BluetoothAdapter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
enableBluetoothButton.setOnClickListener(v ->
{
if (bluetoothAdapter != null && !bluetoothAdapter.isEnabled())
{
bluetoothAdapter.enable();
Toast.makeText(this, "Bluetooth Enabled", Toast.LENGTH_SHORT).show();
}
});
scanDevicesButton.setOnClickListener(v ->
{
if (bluetoothAdapter != null)
{
bluetoothAdapter.startDiscovery();
Toast.makeText(this, "Scanning for Devices", Toast.LENGTH_SHORT).show();
}
});
}
@Override
protected void onDestroy()
{
super.onDestroy();
if (bluetoothAdapter != null) {
bluetoothAdapter.cancelDiscovery();
}
}
}
Activity_main.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/enableBluetoothButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enable Bluetooth" />
<Button
android:id="@+id/scanDevicesButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Scan Devices" />
</LinearLayout>
AndroidManifest.xml
</manifest>
SMS send
MainActivity.java
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;
startActivity(intent);
}
});
}
}
Activity_main.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/btn_send_sms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send SMS" />
</LinearLayout>
MainActivity.java
import android.os.Bundle;
import android.util.Log;
import android.widget.ZoomControls;
import androidx.appcompat.app.AppCompatActivity;
zoomControls.setOnZoomInClickListener(v ->
{
zoomControls.setOnZoomOutClickListener(v ->
{
<ZoomControls
android:id="@+id/zoomControls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
MainActivity.java
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
if (intent.resolveActivity(getPackageManager()) != null)
{
startActivity(intent);
}
}
}
Geo Coding and Reverse Geo coding
MainActivity.java
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.Toast;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
try
{
List<Address> geocodeResult = geocoder.getFromLocationName("1600 Amphitheatre
Parkway, Mountain View, CA", 1);
if (!geocodeResult.isEmpty())
{
Address addr = geocodeResult.get(0);
Toast.makeText(this, "Lat: " + addr.getLatitude() + ", Lon: " + addr.getLongitude(),
Toast.LENGTH_LONG).show();
}
}
catch (IOException e)
{
e.printStackTrace();
}
try
{
List<Address> reverseGeocodeResult = geocoder.getFromLocation(37.4220, -
122.0841, 1);
if (!reverseGeocodeResult.isEmpty())
{
Toast.makeText(this, reverseGeocodeResult.get(0).getAddressLine(0),
Toast.LENGTH_LONG).show();
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
AndroidManifest.xml
</manifest>