PR (30,31)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

Name: Aditya Kumar Sah

android:layout_width="match_parent"
Roll No: 8

Q30)
android:layout_height="wrap_content"
Activity_main.xml:
android:layout_marginTop="8dp"
<?xml version="1.0" encoding="utf-8"?>
android:hint="Subject" />
<LinearLayout
xmlns:android="http://schemas.android.c
om/apk/res/android" <EditText

android:layout_width="match_parent" android:id="@+id/editTextBody"

android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:padding="16dp">
android:layout_height="wrap_content"

android:layout_marginTop="8dp"
<EditText
android:hint="Body"
android:id="@+id/editTextSender"
android:minLines="4"

android:inputType="textMultiLine" />
android:layout_width="match_parent"

android:layout_height="wrap_content" <Button
android:hint="Your Email Address" /> android:id="@+id/buttonSend"

android:layout_width="wrap_content"
<EditText
android:id="@+id/editTextRecipient"
android:layout_height="wrap_content"

android:layout_width="match_parent"
android:layout_gravity="center_horizontal
"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:hint="Recipient Email" />
android:text="Send" />

<EditText
</LinearLayout>
android:id="@+id/editTextSubject"
Name: Aditya Kumar Sah import androidx.core.app.ActivityCompat;

Roll No: 8 import androidx.core.content.ContextCompat;

Q31)
Activity_main.xml: import org.osmdroid.api.IMapController;

<?xml version="1.0" encoding="utf-8"?> import org.osmdroid.config.Configuration;

<RelativeLayout import
xmlns:android="http://schemas.android.com/ org.osmdroid.tileprovider.tilesource.TileSource
apk/res/android" Factory;

import org.osmdroid.util.BoundingBox;
xmlns:tools="http://schemas.android.com/too import org.osmdroid.util.GeoPoint;
ls"
import org.osmdroid.views.MapView;
android:layout_width="match_parent"
import
android:layout_height="match_parent" org.osmdroid.views.overlay.mylocation.GpsMy
tools:context=".MainActivity"> LocationProvider;

import
org.osmdroid.views.overlay.mylocation.MyLoc
<org.osmdroid.views.MapView ationNewOverlay;
android:id="@+id/mapView"

android:layout_width="match_parent" public class MainActivity extends


AppCompatActivity {
android:layout_height="match_parent"
/>

private static final int


LOCATION_PERMISSION_REQUEST_CODE = 1;
</RelativeLayout>
private MapView mapView;
MainActivity.java
private MyLocationNewOverlay
package com.example.practicaal;
myLocationOverlay;

import android.Manifest;
@Override
import android.content.pm.PackageManager;
protected void onCreate(Bundle
import android.os.Bundle; savedInstanceState) {

import android.widget.Toast; super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

import androidx.annotation.NonNull;

import // Initialize osmdroid configuration


androidx.appcompat.app.AppCompatActivity;
Name: Pratham bhoir
android:layout_width="match_parent"
Roll No: 3

Q30) android:layout_height="wrap_content"
Activity_main.xml: android:layout_marginTop="8dp"
<?xml version="1.0" encoding="utf-8"?> android:hint="Subject" />
<LinearLayout
xmlns:android="http://schemas.android.c
om/apk/res/android" <EditText

android:layout_width="match_parent" android:id="@+id/editTextBody"

android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:padding="16dp"> android:layout_height="wrap_content"

android:layout_marginTop="8dp"
<EditText android:hint="Body"
android:id="@+id/editTextSender" android:minLines="4"

android:inputType="textMultiLine" />
android:layout_width="match_parent"

android:layout_height="wrap_content" <Button

android:hint="Your Email Address" /> android:id="@+id/buttonSend"

android:layout_width="wrap_content"
<EditText
android:id="@+id/editTextRecipient" android:layout_height="wrap_content"

android:layout_width="match_parent" android:layout_gravity="center_horizontal
"
android:layout_height="wrap_content" android:layout_marginTop="16dp"
android:hint="Recipient Email" /> android:text="Send" />

<EditText </LinearLayout>
android:id="@+id/editTextSubject"
Name: Prathambhoir import androidx.core.app.ActivityCompat;

Roll No: 3 import androidx.core.content.ContextCompat;

Q31)
import org.osmdroid.api.IMapController;
Activity_main.xml:
import org.osmdroid.config.Configuration;
<?xml version="1.0" encoding="utf-8"?>
import
<RelativeLayout
org.osmdroid.tileprovider.tilesource.TileSource
xmlns:android="http://schemas.android.com/
Factory;
apk/res/android"
import org.osmdroid.util.BoundingBox;
xmlns:tools="http://schemas.android.com/too import org.osmdroid.util.GeoPoint;
ls"
import org.osmdroid.views.MapView;
android:layout_width="match_parent"
import
android:layout_height="match_parent" org.osmdroid.views.overlay.mylocation.GpsMy
LocationProvider;
tools:context=".MainActivity">
import
org.osmdroid.views.overlay.mylocation.MyLoc
<org.osmdroid.views.MapView ationNewOverlay;

android:id="@+id/mapView"

android:layout_width="match_parent" public class MainActivity extends


AppCompatActivity {
android:layout_height="match_parent"
/>

private static final int


LOCATION_PERMISSION_REQUEST_CODE = 1;
</RelativeLayout>
private MapView mapView;
MainActivity.java
private MyLocationNewOverlay
package com.example.practicaal;
myLocationOverlay;

import android.Manifest;
@Override
import android.content.pm.PackageManager;
protected void onCreate(Bundle
import android.os.Bundle; savedInstanceState) {

import android.widget.Toast; super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

import androidx.annotation.NonNull;

import // Initialize osmdroid configuration


androidx.appcompat.app.AppCompatActivity;
Name: Jignesh Kanoujia
android:layout_width="match_parent"
Roll No: 5
Q30)
android:layout_height="wrap_content"
Activity_main.xml:
android:layout_marginTop="8dp"
<?xml version="1.0" encoding="utf-8"?>
android:hint="Subject" />
<LinearLayout
xmlns:android="http://schemas.android.c
om/apk/res/android" <EditText
android:layout_width="match_parent" android:id="@+id/editTextBody"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:padding="16dp">
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
<EditText
android:hint="Body"
android:id="@+id/editTextSender"
android:minLines="4"
android:inputType="textMultiLine" />
android:layout_width="match_parent"

android:layout_height="wrap_content" <Button
android:hint="Your Email Address" /> android:id="@+id/buttonSend"

android:layout_width="wrap_content"
<EditText
android:id="@+id/editTextRecipient"
android:layout_height="wrap_content"

android:layout_width="match_parent"
android:layout_gravity="center_horizontal
"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:hint="Recipient Email" />
android:text="Send" />

<EditText
</LinearLayout>
android:id="@+id/editTextSubject"
MainActivity.java: editTextRecipient =
findViewById(R.id.editTextRecipient);
package com.example.practicaal;
editTextSubject =
findViewById(R.id.editTextSubject);
import android.content.Intent;
editTextBody =
import android.net.Uri; findViewById(R.id.editTextBody);

import android.os.Bundle; buttonSend =


findViewById(R.id.buttonSend);
import android.view.View;
import android.widget.Button;
buttonSend.setOnClickListener(new
import android.widget.EditText;
View.OnClickListener() {
import android.widget.Toast;
@Override
import
public void onClick(View v) {
androidx.appcompat.app.AppCompatActiv
ity; sendEmail();
}

public class MainActivity extends });


AppCompatActivity {
}

EditText editTextSender,
private void sendEmail() {
editTextRecipient, editTextSubject,
editTextBody; String senderEmail =
editTextSender.getText().toString().trim();
Button buttonSend;
String recipientEmail =
editTextRecipient.getText().toString().trim(
@Override );

protected void onCreate(Bundle String subject =


savedInstanceState) { editTextSubject.getText().toString().trim();

super.onCreate(savedInstanceState); String body =


editTextBody.getText().toString().trim();

setContentView(R.layout.activity_main);
Intent intent = new
Intent(Intent.ACTION_SEND);
editTextSender =
findViewById(R.id.editTextSender); intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL,
new String[]{recipientEmail});

intent.putExtra(Intent.EXTRA_SUBJECT,
subject);
intent.putExtra(Intent.EXTRA_TEXT,
body);

// Adding sender's email to the intent


if not empty
if (!senderEmail.isEmpty()) {
intent.putExtra(Intent.EXTRA_CC,
new String[]{senderEmail});
}

if
(intent.resolveActivity(getPackageManage
r()) != null) {

startActivity(Intent.createChooser(intent,
"Send Email"));
} else {
Toast.makeText(MainActivity.this,
"No email app found",
Toast.LENGTH_SHORT).show();
}
}

Output:
Name: Jignesh Kanoujia import androidx.core.app.ActivityCompat;

Roll No: 5 import androidx.core.content.ContextCompat;

Q31)
Activity_main.xml: import org.osmdroid.api.IMapController;

<?xml version="1.0" encoding="utf-8"?> import org.osmdroid.config.Configuration;

<RelativeLayout import
xmlns:android="http://schemas.android.com/ org.osmdroid.tileprovider.tilesource.TileSource
apk/res/android" Factory;

import org.osmdroid.util.BoundingBox;
xmlns:tools="http://schemas.android.com/too import org.osmdroid.util.GeoPoint;
ls"
import org.osmdroid.views.MapView;
android:layout_width="match_parent"
import
android:layout_height="match_parent" org.osmdroid.views.overlay.mylocation.GpsMy
tools:context=".MainActivity"> LocationProvider;

import
org.osmdroid.views.overlay.mylocation.MyLoc
<org.osmdroid.views.MapView ationNewOverlay;
android:id="@+id/mapView"

android:layout_width="match_parent" public class MainActivity extends


AppCompatActivity {
android:layout_height="match_parent"
/>

private static final int


LOCATION_PERMISSION_REQUEST_CODE = 1;
</RelativeLayout>
private MapView mapView;
MainActivity.java
private MyLocationNewOverlay
package com.example.practicaal;
myLocationOverlay;

import android.Manifest;
@Override
import android.content.pm.PackageManager;
protected void onCreate(Bundle
import android.os.Bundle; savedInstanceState) {

import android.widget.Toast; super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

import androidx.annotation.NonNull;

import // Initialize osmdroid configuration


androidx.appcompat.app.AppCompatActivity;
Configuration.getInstance().load(getApplicatio mapView.setScrollableAreaLimitDouble(new
nContext(), getPreferences(MODE_PRIVATE)); BoundingBox(85, 180, -85, -180));

mapView.setMaxZoomLevel(20.0);

// Check if permission is granted mapView.setMinZoomLevel(4.0);

if
(ContextCompat.checkSelfPermission(this, mapView.setHorizontalMapRepetitionEnabled
Manifest.permission.ACCESS_FINE_LOCATION) (false);

!=
PackageManager.PERMISSION_GRANTED) { mapView.setVerticalMapRepetitionEnabled(fal
se);
// Permission is not granted, request it

mapView.setScrollableAreaLimitLatitude(map
ActivityCompat.requestPermissions(this,
View.getTileSystem().getMaxLatitude(),
new mapView.getTileSystem().getMinLatitude(), 0);
String[]{Manifest.permission.ACCESS_FINE_LO
CATION},
// Add a marker for user's location

LOCATION_PERMISSION_REQUEST_CODE); myLocationOverlay = new


MyLocationNewOverlay(new
} else {
GpsMyLocationProvider(this), mapView);
// Permission is granted, setup map

setupMap(); mapView.getOverlays().add(myLocationOverla
y);
}
myLocationOverlay.enableMyLocation();
}

// Zoom to user's location and fit the map


private void setupMap() { into the screen
boolean location_found = false; GeoPoint startPoint =
mapView = findViewById(R.id.mapView); myLocationOverlay.getMyLocation();

if (startPoint != null) {
mapView.setTileSource(TileSourceFactory.MA IMapController mapController =
PNIK); mapView.getController();
mapView.setMultiTouchControls(true); mapController.setCenter(startPoint);

// Calculate a suitable zoom level based


// Set scrollable area limits and disable on the accuracy of the location
map repetition int zoomLevel = (int) (16 -
Math.log(myLocationOverlay.getLastFix().getA
ccuracy()) / Math.log(2));
mapController.setZoom(zoomLevel); if (requestCode ==
LOCATION_PERMISSION_REQUEST_CODE) {
// Calculate the span based on the
accuracy of the location if (grantResults.length > 0 &&
grantResults[0] ==
int latSpanE6 = (int)
PackageManager.PERMISSION_GRANTED) {
(myLocationOverlay.getLastFix().getAccuracy()
* 1E6); // Permission granted, setup map

int lonSpanE6 = (int) setupMap();


(myLocationOverlay.getLastFix().getAccuracy()
} else {
* 1E6);
// Permission denied
// Zoom to fit the span into the screen
Toast.makeText(this, "Permission
mapController.zoomToSpan(latSpanE6,
denied", Toast.LENGTH_SHORT).show();
lonSpanE6);
}
location_found = true;
}
} else {
}
// If user location is not available,
center the map at a default location

GeoPoint defaultLocation = new @Override


GeoPoint(0, 0); // For example, centering at
coordinates (0, 0) protected void onResume() {

super.onResume();
mapView.getController().setCenter(defaultLoc mapView.onResume();
ation);
}
mapView.getController().setZoom(5); //
Set a default zoom level

} @Override

protected void onPause() {

} super.onPause();

mapView.onPause();

@Override }

public void onRequestPermissionsResult(int Build.gradle(module:app):


requestCode, @NonNull String[] permissions,
plugins {
@NonNull int[] grantResults) {
id("com.android.application")

super.onRequestPermissionsResult(requestCo }
de, permissions, grantResults);
android { }

namespace = "com.example.practicaal"

compileSdk = 34 dependencies {

defaultConfig {
implementation("androidx.appcompat:appco
applicationId = "com.example.practicaal"
mpat:1.6.1")
minSdk = 24

targetSdk = 34 implementation("com.google.android.materia
l:material:1.11.0")
versionCode = 1

versionName = "1.0" implementation("androidx.constraintlayout:co


nstraintlayout:2.1.4")

testInstrumentationRunner =
"androidx.test.runner.AndroidJUnitRunner" implementation("androidx.navigation:navigati
on-fragment:2.7.7")
}

implementation("androidx.navigation:navigati
buildTypes { on-ui:2.7.7")

release { implementation("org.osmdroid:osmdroid-
android:6.1.10")
isMinifyEnabled = false
implementation("org.osmdroid:osmdroid-
mapsforge:6.1.10")
proguardFiles(getDefaultProguardFile("progua
rd-android-optimize.txt"), "proguard-
rules.pro") implementation("com.google.android.gms:pla
y-services-maps:18.2.0")
}

} implementation("com.google.android.gms:pla
y-services-location:21.2.0")
compileOptions {
testImplementation("junit:junit:4.13.2")
sourceCompatibility =
JavaVersion.VERSION_1_8
androidTestImplementation("androidx.test.ext
targetCompatibility =
:junit:1.1.5")
JavaVersion.VERSION_1_8

}
androidTestImplementation("androidx.test.es
buildFeatures { presso:espresso-core:3.5.1")

viewBinding = true

}
}
android:theme="@style/Theme.Practicaal"
AndroidManifest.xml:
tools:targetApi="31">
<?xml version="1.0" encoding="utf-8"?>
<activity
<manifest
xmlns:android="http://schemas.android.com/ android:name=".MainActivity2"
apk/res/android"
android:exported="false"

xmlns:tools="http://schemas.android.com/too
android:label="@string/title_activity_main2"
ls">

<uses-permission
android:theme="@style/Theme.Practicaal" />
android:name="android.permission.ACCESS_F
INE_LOCATION" /> <activity

<uses-permission android:name=".MainActivity"
android:name="android.permission.ACCESS_C
android:exported="true"
OARSE_LOCATION" />
android:label="@string/app_name"
<uses-permission
android:name="android.permission.WRITE_EX
TERNAL_STORAGE"/> android:theme="@style/Theme.Practicaal">
<uses-permission <intent-filter>
android:name="android.permission.INTERNET
" /> <action
android:name="android.intent.action.MAIN"
<uses-feature />
android:name="android.hardware.location.gp
s" />

<application <category
android:name="android.intent.category.LAUN
android:allowBackup="true" CHER" />

</intent-filter>
android:dataExtractionRules="@xml/data_ext
raction_rules" </activity>

<receiver android:name=".Broad"
android:fullBackupContent="@xml/backup_ru android:exported="true">
les"
<intent-filter>
android:icon="@mipmap/ic_launcher"
<action
android:label="@string/app_name" android:name="android.intent.action.AIRPLA
NE_MODE"></action>
android:roundIcon="@mipmap/ic_launcher_r </intent-filter>
ound"
</receiver>
android:supportsRtl="true"
</application>

</manifest>

Output:

You might also like