Implemented notification , progress dialog after entering radius of a given location in the Luna application .
This commit is contained in:
		
							parent
							
								
									ef5153765f
								
							
						
					
					
						commit
						7366fc3c64
					
				@ -17,6 +17,8 @@
 | 
				
			|||||||
    <uses-feature android:name="android.hardware.camera.autofocus" />
 | 
					    <uses-feature android:name="android.hardware.camera.autofocus" />
 | 
				
			||||||
    <uses-feature android:name="android.hardware.camera.flash" />
 | 
					    <uses-feature android:name="android.hardware.camera.flash" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <application
 | 
					    <application
 | 
				
			||||||
        android:name=".App"
 | 
					        android:name=".App"
 | 
				
			||||||
        android:allowBackup="false"
 | 
					        android:allowBackup="false"
 | 
				
			||||||
@ -73,6 +75,7 @@
 | 
				
			|||||||
        <activity
 | 
					        <activity
 | 
				
			||||||
            android:name=".authentication.AuthSuccessActivity"
 | 
					            android:name=".authentication.AuthSuccessActivity"
 | 
				
			||||||
            android:screenOrientation="portrait" />
 | 
					            android:screenOrientation="portrait" />
 | 
				
			||||||
 | 
					        <service android:name="ru.Service.MyLocationService"/>
 | 
				
			||||||
    </application>
 | 
					    </application>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
</manifest>
 | 
					</manifest>
 | 
				
			||||||
@ -0,0 +1,351 @@
 | 
				
			|||||||
 | 
					package ru.Service;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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.Service;
 | 
				
			||||||
 | 
					import android.content.Context;
 | 
				
			||||||
 | 
					import android.content.DialogInterface;
 | 
				
			||||||
 | 
					import android.content.Intent;
 | 
				
			||||||
 | 
					import android.content.pm.PackageManager;
 | 
				
			||||||
 | 
					import android.location.Location;
 | 
				
			||||||
 | 
					import android.location.LocationManager;
 | 
				
			||||||
 | 
					import android.os.Build;
 | 
				
			||||||
 | 
					import android.os.Handler;
 | 
				
			||||||
 | 
					import android.os.IBinder;
 | 
				
			||||||
 | 
					import android.provider.Settings;
 | 
				
			||||||
 | 
					import android.widget.Toast;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import androidx.annotation.Nullable;
 | 
				
			||||||
 | 
					import androidx.core.app.ActivityCompat;
 | 
				
			||||||
 | 
					import androidx.core.app.NotificationCompat;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import ru.visionlab.femdemo.CheckInActivity;
 | 
				
			||||||
 | 
					import ru.visionlab.femdemo.R;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class MyLocationService extends Service {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    LocationManager locationManager;
 | 
				
			||||||
 | 
					    private static final int REQUEST_LOCATION = 1;
 | 
				
			||||||
 | 
					    String latitude, longitude;
 | 
				
			||||||
 | 
					    ProgressDialog progressDialog;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Handler handler = new Handler();
 | 
				
			||||||
 | 
					    Runnable runnable;
 | 
				
			||||||
 | 
					    int delay = 10000;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // execution of service will start
 | 
				
			||||||
 | 
					    // on calling this method
 | 
				
			||||||
 | 
					    public int onStartCommand(Intent intent, int flags, int startId) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        System.out.println("Inside my location service");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
 | 
				
			||||||
 | 
					        addNotification();
 | 
				
			||||||
 | 
					        trackGPS();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // returns the status
 | 
				
			||||||
 | 
					        // of the program
 | 
				
			||||||
 | 
					        return START_STICKY;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private void trackGPS() {
 | 
				
			||||||
 | 
					        handler.postDelayed(runnable = new Runnable() {
 | 
				
			||||||
 | 
					            public void run() {
 | 
				
			||||||
 | 
					                handler.postDelayed(runnable, delay);
 | 
				
			||||||
 | 
					                System.out.println("Inside handler");
 | 
				
			||||||
 | 
					                            /*Intent intent = new Intent(MainActivity.this,MyLocationService.class);
 | 
				
			||||||
 | 
					                            startService(intent);*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
 | 
				
			||||||
 | 
					                    OnGPS();
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    getLocation();
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }, delay);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // execution of the service will
 | 
				
			||||||
 | 
					    // stop on calling this method
 | 
				
			||||||
 | 
					    public void onDestroy() {
 | 
				
			||||||
 | 
					        handler.removeCallbacks(runnable);
 | 
				
			||||||
 | 
					        super.onDestroy();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    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");
 | 
				
			||||||
 | 
					        /*NotificationCompat.Builder builder =
 | 
				
			||||||
 | 
					                new NotificationCompat.Builder(this)
 | 
				
			||||||
 | 
					                        .setSmallIcon(R.drawable.ic_launcher_background)
 | 
				
			||||||
 | 
					                        .setContentTitle("Notifications Example")
 | 
				
			||||||
 | 
					                        .setContentText("This is a test notification")
 | 
				
			||||||
 | 
					                        .setPriority(NotificationCompat.PRIORITY_DEFAULT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Intent notificationIntent = new Intent(this, MainActivity.class);
 | 
				
			||||||
 | 
					        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,
 | 
				
			||||||
 | 
					                PendingIntent.FLAG_IMMUTABLE);
 | 
				
			||||||
 | 
					        builder.setContentIntent(contentIntent);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Add as notification
 | 
				
			||||||
 | 
					        NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
 | 
				
			||||||
 | 
					        manager.notify(0, builder.build());*/
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private void locationNotification() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        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("Location notification");
 | 
				
			||||||
 | 
					        bigText.setSummaryText("Entered location perimeter");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        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");
 | 
				
			||||||
 | 
					        /*NotificationCompat.Builder builder =
 | 
				
			||||||
 | 
					                new NotificationCompat.Builder(this)
 | 
				
			||||||
 | 
					                        .setSmallIcon(R.drawable.ic_launcher_background)
 | 
				
			||||||
 | 
					                        .setContentTitle("Notifications Example")
 | 
				
			||||||
 | 
					                        .setContentText("This is a test notification")
 | 
				
			||||||
 | 
					                        .setPriority(NotificationCompat.PRIORITY_DEFAULT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Intent notificationIntent = new Intent(this, MainActivity.class);
 | 
				
			||||||
 | 
					        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,
 | 
				
			||||||
 | 
					                PendingIntent.FLAG_IMMUTABLE);
 | 
				
			||||||
 | 
					        builder.setContentIntent(contentIntent);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Add as notification
 | 
				
			||||||
 | 
					        NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
 | 
				
			||||||
 | 
					        manager.notify(0, builder.build());*/
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private void getLocation() {
 | 
				
			||||||
 | 
					        //Check Permissions again
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
 | 
				
			||||||
 | 
					            // TODO: Consider calling
 | 
				
			||||||
 | 
					            //    ActivityCompat#requestPermissions
 | 
				
			||||||
 | 
					            // here to request the missing permissions, and then overriding
 | 
				
			||||||
 | 
					            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
 | 
				
			||||||
 | 
					            //                                          int[] grantResults)
 | 
				
			||||||
 | 
					            // to handle the case where the user grants the permission. See the documentation
 | 
				
			||||||
 | 
					            // for ActivityCompat#requestPermissions for more details.
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        Location LocationGps = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
 | 
				
			||||||
 | 
					        Location LocationNetwork=locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
 | 
				
			||||||
 | 
					        Location LocationPassive=locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (LocationGps !=null)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            double lat=LocationGps.getLatitude();
 | 
				
			||||||
 | 
					            double longi=LocationGps.getLongitude();
 | 
				
			||||||
 | 
					            /*double newLat = 22.5747;
 | 
				
			||||||
 | 
					            double newLong = 88.4338;*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            double newLat = 22.5796;
 | 
				
			||||||
 | 
					            double newLong = 88.4383;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            float[] results = new float[1];
 | 
				
			||||||
 | 
					            Location.distanceBetween(lat,longi,newLat,newLong,results);
 | 
				
			||||||
 | 
					            float distance = results[0];
 | 
				
			||||||
 | 
					            Toast.makeText(this,String.valueOf(distance)+" metres from location",Toast.LENGTH_LONG).show();
 | 
				
			||||||
 | 
					            if(distance > 400){
 | 
				
			||||||
 | 
					                Toast.makeText(this,"You are outside location range",Toast.LENGTH_LONG).show();
 | 
				
			||||||
 | 
					                System.out.println("You are outside location range");
 | 
				
			||||||
 | 
					                System.out.println("Position 1 ");
 | 
				
			||||||
 | 
					                //moreThanFour();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            else{
 | 
				
			||||||
 | 
					                Toast.makeText(this,"You are inside location range",Toast.LENGTH_LONG).show();
 | 
				
			||||||
 | 
					                locationNotification();
 | 
				
			||||||
 | 
					                System.out.println("You are inside location range");
 | 
				
			||||||
 | 
					                System.out.println("Position 2 ");
 | 
				
			||||||
 | 
					                //lessThanFour();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            latitude=String.valueOf(lat);
 | 
				
			||||||
 | 
					            longitude=String.valueOf(longi);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            latitude=String.valueOf(lat);
 | 
				
			||||||
 | 
					            longitude=String.valueOf(longi);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            System.out.println("Inside getLocation");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else if (LocationNetwork !=null)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            System.out.println("Position 3 ");
 | 
				
			||||||
 | 
					            double lat=LocationNetwork.getLatitude();
 | 
				
			||||||
 | 
					            double longi=LocationNetwork.getLongitude();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            double newLat = 22.5747;
 | 
				
			||||||
 | 
					            double newLong = 88.4338;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            float[] results = new float[1];
 | 
				
			||||||
 | 
					            Location.distanceBetween(lat,longi,newLat,newLong,results);
 | 
				
			||||||
 | 
					            float distance = results[0];
 | 
				
			||||||
 | 
					            Toast.makeText(this,String.valueOf(distance)+" metres from location",Toast.LENGTH_LONG).show();
 | 
				
			||||||
 | 
					            if(distance > 400){
 | 
				
			||||||
 | 
					                Toast.makeText(this,"You are outside location range",Toast.LENGTH_LONG).show();
 | 
				
			||||||
 | 
					                System.out.println("You are outside location range");
 | 
				
			||||||
 | 
					                //moreThanFour();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            else{
 | 
				
			||||||
 | 
					                Toast.makeText(this,"You are inside location range",Toast.LENGTH_LONG).show();
 | 
				
			||||||
 | 
					                System.out.println("You are inside location range");
 | 
				
			||||||
 | 
					                //lessThanFour();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            latitude=String.valueOf(lat);
 | 
				
			||||||
 | 
					            longitude=String.valueOf(longi);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            latitude=String.valueOf(lat);
 | 
				
			||||||
 | 
					            longitude=String.valueOf(longi);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else if (LocationPassive !=null)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            double lat=LocationPassive.getLatitude();
 | 
				
			||||||
 | 
					            double longi=LocationPassive.getLongitude();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            latitude=String.valueOf(lat);
 | 
				
			||||||
 | 
					            longitude=String.valueOf(longi);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            // Toast.makeText(this, "Can't Get Your Location", Toast.LENGTH_SHORT).show();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            double lat=LocationNetwork.getLatitude();
 | 
				
			||||||
 | 
					            double longi=LocationNetwork.getLongitude();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            double newLat = 22.5747;
 | 
				
			||||||
 | 
					            double newLong = 88.4338;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            float[] results = new float[1];
 | 
				
			||||||
 | 
					            Location.distanceBetween(lat,longi,newLat,newLong,results);
 | 
				
			||||||
 | 
					            float distance = results[0];
 | 
				
			||||||
 | 
					            Toast.makeText(this,String.valueOf(distance)+" metres from location",Toast.LENGTH_LONG).show();
 | 
				
			||||||
 | 
					            if(distance > 400){
 | 
				
			||||||
 | 
					                Toast.makeText(this,"You are outside location range",Toast.LENGTH_LONG).show();
 | 
				
			||||||
 | 
					                System.out.println("You are outside location range");
 | 
				
			||||||
 | 
					                //moreThanFour();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            else{
 | 
				
			||||||
 | 
					                Toast.makeText(this,"You are inside location range",Toast.LENGTH_LONG).show();
 | 
				
			||||||
 | 
					                System.out.println("You are inside location range");
 | 
				
			||||||
 | 
					                //lessThanFour();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //Thats All Run Your App
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private void OnGPS() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        final AlertDialog.Builder builder= new AlertDialog.Builder(this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        builder.setMessage("Enable GPS").setCancelable(false).setPositiveButton("YES", new DialogInterface.OnClickListener() {
 | 
				
			||||||
 | 
					            @Override
 | 
				
			||||||
 | 
					            public void onClick(DialogInterface dialog, int which) {
 | 
				
			||||||
 | 
					                startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }).setNegativeButton("NO", new DialogInterface.OnClickListener() {
 | 
				
			||||||
 | 
					            @Override
 | 
				
			||||||
 | 
					            public void onClick(DialogInterface dialog, int which) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                dialog.cancel();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					        final AlertDialog alertDialog=builder.create();
 | 
				
			||||||
 | 
					        alertDialog.show();
 | 
				
			||||||
 | 
					        System.out.println("Inside OnGPS");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    @Nullable
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public IBinder onBind(Intent intent) {
 | 
				
			||||||
 | 
					        return null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -4,6 +4,7 @@ import androidx.appcompat.app.AppCompatActivity;
 | 
				
			|||||||
import androidx.core.app.ActivityCompat;
 | 
					import androidx.core.app.ActivityCompat;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import android.app.AlertDialog;
 | 
					import android.app.AlertDialog;
 | 
				
			||||||
 | 
					import android.app.ProgressDialog;
 | 
				
			||||||
import android.content.Context;
 | 
					import android.content.Context;
 | 
				
			||||||
import android.content.DialogInterface;
 | 
					import android.content.DialogInterface;
 | 
				
			||||||
import android.content.Intent;
 | 
					import android.content.Intent;
 | 
				
			||||||
@ -13,6 +14,7 @@ import android.graphics.drawable.ColorDrawable;
 | 
				
			|||||||
import android.location.Location;
 | 
					import android.location.Location;
 | 
				
			||||||
import android.location.LocationManager;
 | 
					import android.location.LocationManager;
 | 
				
			||||||
import android.os.Bundle;
 | 
					import android.os.Bundle;
 | 
				
			||||||
 | 
					import android.os.Handler;
 | 
				
			||||||
import android.provider.Settings;
 | 
					import android.provider.Settings;
 | 
				
			||||||
import android.view.Gravity;
 | 
					import android.view.Gravity;
 | 
				
			||||||
import android.view.LayoutInflater;
 | 
					import android.view.LayoutInflater;
 | 
				
			||||||
@ -26,6 +28,7 @@ import android.widget.TextView;
 | 
				
			|||||||
import android.widget.Toast;
 | 
					import android.widget.Toast;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import cn.pedant.SweetAlert.SweetAlertDialog;
 | 
					import cn.pedant.SweetAlert.SweetAlertDialog;
 | 
				
			||||||
 | 
					import ru.Service.MyLocationService;
 | 
				
			||||||
import ru.visionlab.femdemo.login.LoginActivity;
 | 
					import ru.visionlab.femdemo.login.LoginActivity;
 | 
				
			||||||
import ru.visionlab.femdemo.register.RegisterActivityNew;
 | 
					import ru.visionlab.femdemo.register.RegisterActivityNew;
 | 
				
			||||||
import ru.visionlab.femdemo.views.EmployeeActivity;
 | 
					import ru.visionlab.femdemo.views.EmployeeActivity;
 | 
				
			||||||
@ -39,10 +42,16 @@ public class CheckInActivity extends AppCompatActivity {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    AlertDialog dialogBuilder;
 | 
					    AlertDialog dialogBuilder;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Button btnCheckIn;
 | 
					    Button btnCheckIn,btncheckOut;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    LocationManager locationManager;
 | 
					    LocationManager locationManager;
 | 
				
			||||||
    String latitude,longitude;
 | 
					    String latitude,longitude;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ProgressDialog progressDialog;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Handler handler = new Handler();
 | 
				
			||||||
 | 
					    Runnable runnable;
 | 
				
			||||||
 | 
					    int delay = 10000;
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    protected void onCreate(Bundle savedInstanceState) {
 | 
					    protected void onCreate(Bundle savedInstanceState) {
 | 
				
			||||||
        super.onCreate(savedInstanceState);
 | 
					        super.onCreate(savedInstanceState);
 | 
				
			||||||
@ -57,8 +66,26 @@ public class CheckInActivity extends AppCompatActivity {
 | 
				
			|||||||
                /*Intent intent = new Intent(CheckInActivity.this, EmployeeActivity.class);
 | 
					                /*Intent intent = new Intent(CheckInActivity.this, EmployeeActivity.class);
 | 
				
			||||||
                startActivity(intent);*/
 | 
					                startActivity(intent);*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                location();
 | 
					                //location();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                progressDialog = new ProgressDialog(CheckInActivity.this);
 | 
				
			||||||
 | 
					                progressDialog.setTitle("");
 | 
				
			||||||
 | 
					                progressDialog.setMessage("Loading this Content, please wait!");
 | 
				
			||||||
 | 
					                progressDialog.show();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                startService(new Intent(CheckInActivity.this, MyLocationService.class));
 | 
				
			||||||
 | 
					                progressDialog.dismiss();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        btncheckOut = findViewById(R.id.btncheckOut);
 | 
				
			||||||
 | 
					        btncheckOut.setOnClickListener(new View.OnClickListener() {
 | 
				
			||||||
 | 
					            @Override
 | 
				
			||||||
 | 
					            public void onClick(View view) {
 | 
				
			||||||
 | 
					                Toast.makeText(CheckInActivity.this,"Stopping service",Toast.LENGTH_LONG).show();
 | 
				
			||||||
 | 
					                stopService(new Intent(CheckInActivity.this, MyLocationService.class));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -60,6 +60,7 @@
 | 
				
			|||||||
        android:gravity="center"/>
 | 
					        android:gravity="center"/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <Button
 | 
					    <Button
 | 
				
			||||||
 | 
					        android:id="@+id/btncheckOut"
 | 
				
			||||||
        android:layout_width="match_parent"
 | 
					        android:layout_width="match_parent"
 | 
				
			||||||
        android:layout_height="wrap_content"
 | 
					        android:layout_height="wrap_content"
 | 
				
			||||||
        android:layout_marginTop="20dp"
 | 
					        android:layout_marginTop="20dp"
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user