6
6
6
<ImageView
android:id="@+id/imgV"
android:layout_height="400dp"
android:layout_width="match_parent"/>
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Capture Image"/>
</LinearLayout>
______________________________
package com.example.cam;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv = findViewById(R.id.imgV);
b = findViewById(R.id.btn);
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivityForResult(new
Intent(MediaStore.ACTION_IMAGE_CAPTURE),REQ_CODE);
}
});
@Override
protected void onActivityResult(int reqCode, int resCode, Intent data) {
super.onActivityResult(reqCode, resCode, data);
6_2 :
package com.example.email;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.widget.Button;
import android.widget.EditText;
Button button;
EditText to, sub, body;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
to = findViewById(R.id.editText1);
sub = findViewById(R.id.editText2);
body = findViewById(R.id.editText3);
button = findViewById(R.id.button);
button.setOnClickListener(view -> {
String emailsend = to.getText().toString();
String emailsubject = sub.getText().toString();
String emailbody = body.getText().toString();
intent.setType("message/rfc822");
_____________________________________________
---------------------------------------------
6_3 :
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TableRow >
<EditText
android:id="@+id/en1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter No.1" />
</TableRow>
<TableRow >
<EditText
android:id="@+id/en2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter No.2 "
/>
</TableRow>
<TableRow >
<TextView
android:id="@+id/res"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="22dp"
android:text="Result : "
/>
</TableRow>
<TableRow >
<Button
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+" />
<Button
android:id="@+id/sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-" />
<Button
android:id="@+id/mul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="*" />
<Button
android:id="@+id/div"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/" />
</TableRow>
</TableLayout>
----------------------
package com.example.cal;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle s) {
super.onCreate(s);
setContentView(R.layout.activity_main);
// Initialize UI components
en1 = findViewById(R.id.en1);
en2 = findViewById(R.id.en2);
res = findViewById(R.id.res);
add = findViewById(R.id.add);
sub = findViewById(R.id.sub);
mul = findViewById(R.id.mul);
div = findViewById(R.id.div);
mul.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
calculate('*');
}
});
div.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
calculate('/');
}
});
}
float n1 = Float.parseFloat(en1.getText().toString());
float n2 = Float.parseFloat(en2.getText().toString());
double result;
switch (operator) {
case '+':
result = n1 + n2;
break;
case '-':
result = n1 - n2;
break;
case '*':
result = n1 * n2;
break;
case '/':
if (n2 == 0) {
Toast.makeText(this, "Cannot divide by zero",
Toast.LENGTH_SHORT).show();
return;
}
result = n1 / n2;
break;
default:
return;
}
---------------------------------
________________________________
6_5 :
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/map"/>
</RelativeLayout>
-------------------------------------
package com.example.carloaction;
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import com.google.android.gms.location.*;
import com.google.android.gms.maps.*;
import com.google.android.gms.maps.model.*;
import android.location.Location;
import com.google.android.gms.tasks.*;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
flpc = LocationServices.getFusedLocationProviderClient(this);
fetchLastLocation();
}
@Override
public void onMapReady(@NonNull GoogleMap googleMap) {
if (carLoc != null) {
LatLng latLng = new LatLng(carLoc.getLatitude(),
carLoc.getLongitude());
googleMap.addMarker(new MarkerOptions().position(latLng).title("Your
Car"));
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng,
15F));
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[]
permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == REQ_CODE && grantResults.length > 0 && grantResults[0]
== PackageManager.PERMISSION_GRANTED) {
fetchLastLocation();
}
}
}