Codes-
Codes-
package com.example.displaygooglemapwithcurrloc;
import android.Manifest;
import android.os.*;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import com.google.android.gms.location.*;
import com.google.android.gms.maps.*;
import com.google.android.gms.maps.model.*;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
flpc = LocationServices.getFusedLocationProviderClient(this);
@Override
public void onMapReady(GoogleMap gmap) {
mMap = gmap;
if (checkPermission()) {
getCurrentLoc();
}
}
}
}
@Override
public void onRequestPermissionsResult(int rc, String[] p, int[] gr) {
super.onRequestPermissionsResult(rc, p, gr);
if (rc == 100 && gr.length > 0 && gr[0] == 0) {
getCurrentLoc();
}
}
}
import android.Manifest;
import android.graphics.Color;
import android.os.*;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import com.google.android.gms.location.*;
import com.google.android.gms.maps.*;
import com.google.android.gms.maps.model.*;
public class MainActivity extends AppCompatActivity implements OnMapReadyC
allback {
GoogleMap mMap;
FusedLocationProviderClient flpc;
private final LatLng MSBTE_LOCATION = new LatLng(19.063767, 72.8427585);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
flpc = LocationServices.getFusedLocationProviderClient(this);
@Override
public void onMapReady(GoogleMap gmap) {
mMap = gmap;
if (checkPermission()) {
getRoute();
}
}
flpc.getCurrentLocation(
100,
null
).addOnSuccessListener(
this, loc -> {
if (loc != null) {
LatLng uLoc = new LatLng(loc.getLatitude(), loc.
getLongitude());
mMap.addMarker(new MarkerOptions()
.position(uLoc)
.title("Current Location"));
mMap.addPolyline(new PolylineOptions()
.add(uLoc, MSBTE_LOCATION)
.width(5)
.color(Color.BLUE));
mMap.moveCamera(CameraUpdateFactory.newLatLngZo
om(
new LatLng(
(uLoc.latitude + MSBTE_LOCATION.
latitude) / 2,
(uLoc.longitude + MSBTE_LOCATIO
N.longitude) / 2
), 12)
);
}
}
);
}
}
@Override
public void onRequestPermissionsResult(int rc, String[] p, int[] gr) {
super.onRequestPermissionsResult(rc, p, gr);
if (rc == 100 && gr.length > 0 && gr[0] == 0) {
getRoute();
}
}
}
<EditText
android:id="@+id/e1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Phone Number" />
<EditText
android:id="@+id/e2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Message" />
<Button
android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Send SMS" />
<TextView
android:id="@+id/t1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
package com.example.displaygooglemapwithcurrloc;
import android.Manifest;
import android.content.*;
import android.os.*;
import android.provider.Telephony;
import android.telephony.*;
import android.widget.*;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.btn).setOnClickListener(v -> {
String pno = ((EditText) findViewById(R.id.e1)).getText().toStr
ing();
String mess = ((EditText) findViewById(R.id.e2)).getText().toSt
ring();
sms.sendTextMessage(pno, null, mess, null, null);
Toast.makeText(this, "SMS sent!", Toast.LENGTH_SHORT).show();
});
}
public void checkPermission() {
if (ContextCompat.checkSelfPermission(
this,
Manifest.permission.SEND_SMS
) == -1 && ContextCompat.checkSelfPermission(
this,
Manifest.permission.RECEIVE_SMS
) == -1) {
ActivityCompat.requestPermissions(
this,
new String[]{
Manifest.permission.SEND_SMS,
Manifest.permission.RECEIVE_SMS
},
100
);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(br);
}
}
4 Send Email
<EditText
android:id="@+id/e1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email ID" />
<EditText
android:id="@+id/e2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Subject" />
<EditText
android:id="@+id/e3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Message" />
<Button
android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Send Email" />
</LinearLayout>
package com.example.displaygooglemapwithcurrloc;
import android.content.Intent;
import android.os.Bundle;
import android.widget.*;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.btn).setOnClickListener(v -> {
String to = ((EditText) findViewById(R.id.e1)).getText().toStri
ng();
String sub = ((EditText) findViewById(R.id.e2)).getText().toStr
ing();
String mess = ((EditText) findViewById(R.id.e3)).getText().toSt
ring();
<ImageView
android:id="@+id/img"
android:layout_width="300dp"
android:layout_height="300dp" />
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Image"/>
</LinearLayout>
package com.example.displaygooglemapwithcurrloc;
import android.Manifest;
import android.content.*;
import android.graphics.*;
import android.os.Bundle;
import android.provider.*;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
findViewById(R.id.btn).setOnClickListener(v -> {
if(ContextCompat.checkSelfPermission(
this,
Manifest.permission.CAMERA
) == -1) {
ActivityCompat.requestPermissions(
this,
new String[]{
Manifest.permission.CAMERA
},
100
);
}
else {
startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_C
APTURE), 1);
}
});
}
@Override
protected void onActivityResult(int req, int res, Intent it) {
super.onActivityResult(req, res, it);
if (req == 1 && res == -1) {
Bitmap map = (Bitmap) it.getExtras().get("data");
((ImageView) findViewById(R.id.img)).setImageBitmap(map);
}
}
}