diff --git a/examples/example_bestshot/example/app/src/main/java/ru/Service/MyLocationService.java b/examples/example_bestshot/example/app/src/main/java/ru/Service/MyLocationService.java index b2b90ed..ca88100 100644 --- a/examples/example_bestshot/example/app/src/main/java/ru/Service/MyLocationService.java +++ b/examples/example_bestshot/example/app/src/main/java/ru/Service/MyLocationService.java @@ -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) diff --git a/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/CheckInActivity.java b/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/CheckInActivity.java index d29476f..d961710 100644 --- a/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/CheckInActivity.java +++ b/examples/example_bestshot/example/app/src/main/java/ru/visionlab/femdemo/CheckInActivity.java @@ -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")