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)
This commit is contained in:
parent
24dc3f6a9b
commit
c459dc9a8d
@ -47,7 +47,7 @@ public class MyLocationService extends Service {
|
|||||||
System.out.println("Inside my location service");
|
System.out.println("Inside my location service");
|
||||||
|
|
||||||
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
||||||
addNotification();
|
//addNotification();
|
||||||
trackGPS();
|
trackGPS();
|
||||||
|
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ public class MyLocationService extends Service {
|
|||||||
} else {
|
} else {
|
||||||
getLocation();
|
getLocation();
|
||||||
}*/
|
}*/
|
||||||
|
locationNotification();
|
||||||
Toast.makeText(getApplicationContext(),"You are currently near location",Toast.LENGTH_LONG).show();
|
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.setContentIntent(pendingIntent);
|
||||||
mBuilder.setSmallIcon(R.mipmap.ic_launcher);
|
mBuilder.setSmallIcon(R.mipmap.ic_launcher);
|
||||||
mBuilder.setContentTitle("Service started");
|
mBuilder.setContentTitle("Location notification");
|
||||||
mBuilder.setContentText("Location getting tracked");
|
mBuilder.setContentText("Entered location perimeter");
|
||||||
mBuilder.setPriority(Notification.PRIORITY_MAX);
|
mBuilder.setPriority(Notification.PRIORITY_MAX);
|
||||||
mBuilder.setStyle(bigText);
|
mBuilder.setStyle(bigText);
|
||||||
|
|
||||||
@ -181,7 +181,7 @@ public class MyLocationService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mNotificationManager.notify(0, mBuilder.build());
|
mNotificationManager.notify(0, mBuilder.build());
|
||||||
System.out.println("Inside add notific");
|
System.out.println("Inside location notification");
|
||||||
/*NotificationCompat.Builder builder =
|
/*NotificationCompat.Builder builder =
|
||||||
new NotificationCompat.Builder(this)
|
new NotificationCompat.Builder(this)
|
||||||
.setSmallIcon(R.drawable.ic_launcher_background)
|
.setSmallIcon(R.drawable.ic_launcher_background)
|
||||||
|
@ -2,9 +2,14 @@ package ru.visionlab.femdemo;
|
|||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
|
import androidx.core.app.NotificationCompat;
|
||||||
|
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.AlertDialog;
|
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.app.ProgressDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
@ -14,6 +19,7 @@ import android.graphics.Color;
|
|||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
@ -81,14 +87,14 @@ public class CheckInActivity extends AppCompatActivity {
|
|||||||
startService(new Intent(CheckInActivity.this, MyLocationService.class));
|
startService(new Intent(CheckInActivity.this, MyLocationService.class));
|
||||||
progressDialog.dismiss();*/
|
progressDialog.dismiss();*/
|
||||||
|
|
||||||
btnCheckIn.setVisibility(View.INVISIBLE);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
btncheckOut = findViewById(R.id.btncheckOut);
|
btncheckOut = findViewById(R.id.btncheckOut);
|
||||||
|
btncheckOut.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
btncheckOut.setOnClickListener(new View.OnClickListener() {
|
btncheckOut.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -96,6 +102,7 @@ public class CheckInActivity extends AppCompatActivity {
|
|||||||
Toast.makeText(CheckInActivity.this,"Stopping service",Toast.LENGTH_LONG).show();
|
Toast.makeText(CheckInActivity.this,"Stopping service",Toast.LENGTH_LONG).show();
|
||||||
stopService(new Intent(CheckInActivity.this, MyLocationService.class));
|
stopService(new Intent(CheckInActivity.this, MyLocationService.class));
|
||||||
btnCheckIn.setVisibility(View.VISIBLE);
|
btnCheckIn.setVisibility(View.VISIBLE);
|
||||||
|
btncheckOut.setVisibility(View.INVISIBLE);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -260,11 +267,11 @@ public class CheckInActivity extends AppCompatActivity {
|
|||||||
double lat=LocationNetwork.getLatitude();
|
double lat=LocationNetwork.getLatitude();
|
||||||
double longi=LocationNetwork.getLongitude();
|
double longi=LocationNetwork.getLongitude();
|
||||||
|
|
||||||
/*double newLat = 22.5135;
|
double newLat = 22.5118;
|
||||||
double newLong = 88.4029;*/
|
double newLong = 88.4001;
|
||||||
|
|
||||||
double newLat = 22.5150;
|
/*double newLat = 22.5150;
|
||||||
double newLong = 88.3930;
|
double newLong = 88.3930; */
|
||||||
|
|
||||||
float[] results = new float[1];
|
float[] results = new float[1];
|
||||||
Location.distanceBetween(lat,longi,newLat,newLong,results);
|
Location.distanceBetween(lat,longi,newLat,newLong,results);
|
||||||
@ -305,9 +312,11 @@ public class CheckInActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void moreThanFour(){
|
public void moreThanFour(){
|
||||||
|
|
||||||
|
stopService(new Intent(CheckInActivity.this, MyLocationService.class));
|
||||||
btncheckOut.setClickable(false);
|
btncheckOut.setClickable(false);
|
||||||
new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
|
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")
|
.setContentText("Please be in your precise location")
|
||||||
.setConfirmText("OK").setConfirmText("OK").setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
|
.setConfirmText("OK").setConfirmText("OK").setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -318,6 +327,49 @@ public class CheckInActivity extends AppCompatActivity {
|
|||||||
.show();
|
.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(){
|
public void lessThanFour(){
|
||||||
progressDialog = new ProgressDialog(CheckInActivity.this);
|
progressDialog = new ProgressDialog(CheckInActivity.this);
|
||||||
progressDialog.setTitle("");
|
progressDialog.setTitle("");
|
||||||
@ -325,10 +377,13 @@ public class CheckInActivity extends AppCompatActivity {
|
|||||||
progressDialog.show();
|
progressDialog.show();
|
||||||
|
|
||||||
|
|
||||||
|
addNotification();
|
||||||
|
|
||||||
|
|
||||||
startService(new Intent(CheckInActivity.this, MyLocationService.class));
|
startService(new Intent(CheckInActivity.this, MyLocationService.class));
|
||||||
progressDialog.dismiss();
|
progressDialog.dismiss();
|
||||||
|
btnCheckIn.setVisibility(View.INVISIBLE);
|
||||||
|
btncheckOut.setVisibility(View.VISIBLE);
|
||||||
new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE)
|
new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE)
|
||||||
.setTitleText("You are currently near location")
|
.setTitleText("You are currently near location")
|
||||||
.setContentText("Attendance can be captured now")
|
.setContentText("Attendance can be captured now")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user