Browse Source

If service is on check out is visible if not check in is visible . (Done)

Check in will be invisible only if inside location or else not . (Done)

Service and location tracking notification is only active when the user is within 400 metres of the precise location . Service , notification and the check out button will not work when the user is outside 400 metres to the precise location . (Done)
master
Apalak Dutta 1 year ago
parent
commit
c459dc9a8d
2 changed files with 68 additions and 13 deletions
  1. +5
    -5
      examples/example_bestshot/example/app/src/main/java/ru/Service/MyLocationService.java
  2. +63
    -8
      examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/CheckInActivity.java

+ 5
- 5
examples/example_bestshot/example/app/src/main/java/ru/Service/MyLocationService.java View File

@ -47,7 +47,7 @@ public class MyLocationService extends Service {
System.out.println("Inside my location service");
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
addNotification();
//addNotification();
trackGPS();
@ -70,7 +70,7 @@ public class MyLocationService extends Service {
} else {
getLocation();
}*/
locationNotification();
Toast.makeText(getApplicationContext(),"You are currently near location",Toast.LENGTH_LONG).show();
}
@ -160,8 +160,8 @@ public class MyLocationService extends Service {
mBuilder.setContentIntent(pendingIntent);
mBuilder.setSmallIcon(R.mipmap.ic_launcher);
mBuilder.setContentTitle("Service started");
mBuilder.setContentText("Location getting tracked");
mBuilder.setContentTitle("Location notification");
mBuilder.setContentText("Entered location perimeter");
mBuilder.setPriority(Notification.PRIORITY_MAX);
mBuilder.setStyle(bigText);
@ -181,7 +181,7 @@ public class MyLocationService extends Service {
}
mNotificationManager.notify(0, mBuilder.build());
System.out.println("Inside add notific");
System.out.println("Inside location notification");
/*NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher_background)


+ 63
- 8
examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/CheckInActivity.java View File

@ -2,9 +2,14 @@ package ru.visionlab.femdemo;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.app.NotificationCompat;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
@ -14,6 +19,7 @@ import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.location.Location;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
@ -81,14 +87,14 @@ public class CheckInActivity extends AppCompatActivity {
startService(new Intent(CheckInActivity.this, MyLocationService.class));
progressDialog.dismiss();*/
btnCheckIn.setVisibility(View.INVISIBLE);
}
});
btncheckOut = findViewById(R.id.btncheckOut);
btncheckOut.setVisibility(View.INVISIBLE);
btncheckOut.setOnClickListener(new View.OnClickListener() {
@Override
@ -96,6 +102,7 @@ public class CheckInActivity extends AppCompatActivity {
Toast.makeText(CheckInActivity.this,"Stopping service",Toast.LENGTH_LONG).show();
stopService(new Intent(CheckInActivity.this, MyLocationService.class));
btnCheckIn.setVisibility(View.VISIBLE);
btncheckOut.setVisibility(View.INVISIBLE);
}
});
@ -260,11 +267,11 @@ public class CheckInActivity extends AppCompatActivity {
double lat=LocationNetwork.getLatitude();
double longi=LocationNetwork.getLongitude();
/*double newLat = 22.5135;
double newLong = 88.4029;*/
double newLat = 22.5118;
double newLong = 88.4001;
double newLat = 22.5150;
double newLong = 88.3930;
/*double newLat = 22.5150;
double newLong = 88.3930; */
float[] results = new float[1];
Location.distanceBetween(lat,longi,newLat,newLong,results);
@ -305,9 +312,11 @@ public class CheckInActivity extends AppCompatActivity {
}
public void moreThanFour(){
stopService(new Intent(CheckInActivity.this, MyLocationService.class));
btncheckOut.setClickable(false);
new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
.setTitleText("Are you sure you are near location?")
.setTitleText("Stopping service as you are not in location")
.setContentText("Please be in your precise location")
.setConfirmText("OK").setConfirmText("OK").setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
@Override
@ -318,6 +327,49 @@ public class CheckInActivity extends AppCompatActivity {
.show();
}
private void addNotification() {
System.out.println("Inside addNotification");
NotificationManager mNotificationManager;
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(getApplicationContext(), "notify_001");
Intent ii = new Intent(getApplicationContext(), CheckInActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, ii, PendingIntent.FLAG_IMMUTABLE);
NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
bigText.setBigContentTitle("Service started ");
bigText.setSummaryText("Location getting tracked ");
mBuilder.setContentIntent(pendingIntent);
mBuilder.setSmallIcon(R.mipmap.ic_launcher);
mBuilder.setContentTitle("Service started");
mBuilder.setContentText("Location getting tracked");
mBuilder.setPriority(Notification.PRIORITY_MAX);
mBuilder.setStyle(bigText);
mNotificationManager =
(NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
// === Removed some obsoletes
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
{
String channelId = "Your_channel_id";
NotificationChannel channel = new NotificationChannel(
channelId,
"Channel human readable title",
NotificationManager.IMPORTANCE_HIGH);
mNotificationManager.createNotificationChannel(channel);
mBuilder.setChannelId(channelId);
}
mNotificationManager.notify(0, mBuilder.build());
System.out.println("Inside add notific");
}
public void lessThanFour(){
progressDialog = new ProgressDialog(CheckInActivity.this);
progressDialog.setTitle("");
@ -325,10 +377,13 @@ public class CheckInActivity extends AppCompatActivity {
progressDialog.show();
addNotification();
startService(new Intent(CheckInActivity.this, MyLocationService.class));
progressDialog.dismiss();
btnCheckIn.setVisibility(View.INVISIBLE);
btncheckOut.setVisibility(View.VISIBLE);
new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE)
.setTitleText("You are currently near location")
.setContentText("Attendance can be captured now")


Loading…
Cancel
Save