From d473e69e47cb95858d8d697643889abe9cca748a Mon Sep 17 00:00:00 2001 From: Zameel Date: Tue, 26 May 2020 00:35:55 +0530 Subject: [PATCH] some improvements --- .../services/CustomService.java | 24 ++++++++++++------- .../example/acmcovidapplication/share.java | 24 +++++++++---------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/mobile-app/app/src/main/java/com/example/acmcovidapplication/services/CustomService.java b/mobile-app/app/src/main/java/com/example/acmcovidapplication/services/CustomService.java index 45eddcf..475ad48 100644 --- a/mobile-app/app/src/main/java/com/example/acmcovidapplication/services/CustomService.java +++ b/mobile-app/app/src/main/java/com/example/acmcovidapplication/services/CustomService.java @@ -82,9 +82,9 @@ public class CustomService extends Service implements BeaconConsumer, LifecycleO public boolean isLocationTrackable; private int LOCATION_UPDATE_INTERVAL; - private boolean isGpsProviderEnable ; - private boolean isNetworkProviderEnable ; - private boolean isPassiveProviderEnable ; + private boolean isGpsProviderEnable; + private boolean isNetworkProviderEnable; + private boolean isPassiveProviderEnable; private static String ACTION_LOCATION_ACCESS_STATE_CHANGE = "acmcovidapplication.services.location_state_changed"; public static final String ACTION_PROVIDERS_CHANGED = "android.location.PROVIDERS_CHANGED"; public static final String ACTION_KEEP_TRANSMITTER_ALIVE = "acmcovidapplication.services.keep_transmitter_alive"; @@ -129,14 +129,20 @@ public void onCreate() { locationManager = (LocationManager) this .getSystemService(Context.LOCATION_SERVICE); - if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED - && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { - //locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, LOCATION_UPDATE_INTERVAL * 1000, 100, mLocationListener); - locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, LOCATION_UPDATE_INTERVAL * 1000, 100, mLocationListener); - locationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, LOCATION_UPDATE_INTERVAL * 1000, 100, mLocationListener); - + if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, 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. + stopSelf(); return; } + locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, LOCATION_UPDATE_INTERVAL * 1000, 100, mLocationListener); + locationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, LOCATION_UPDATE_INTERVAL * 1000, 100, mLocationListener); + networkStateReceiver.addListener(this); registerBroadcastReceivers(); diff --git a/mobile-app/app/src/main/java/com/example/acmcovidapplication/share.java b/mobile-app/app/src/main/java/com/example/acmcovidapplication/share.java index 1bd3679..5f8a7a2 100644 --- a/mobile-app/app/src/main/java/com/example/acmcovidapplication/share.java +++ b/mobile-app/app/src/main/java/com/example/acmcovidapplication/share.java @@ -1,24 +1,25 @@ package com.example.acmcovidapplication; -import androidx.appcompat.app.AppCompatActivity; -import androidx.core.content.ContextCompat; -import pub.devrel.easypermissions.EasyPermissions; - import android.content.Intent; -import android.os.Build; import android.os.Bundle; import android.view.View; import com.example.acmcovidapplication.services.CustomService; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.content.ContextCompat; +import pub.devrel.easypermissions.EasyPermissions; + public class share extends AppCompatActivity { String[] permissions = Util.getPermissions(); + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_share); } + public void shareApp(View view) { Intent sendIntent = new Intent(); @@ -34,13 +35,12 @@ public void shareApp(View view) { protected void onResume() { super.onResume(); if (!EasyPermissions.hasPermissions(this, permissions)) { - if (!EasyPermissions.hasPermissions(this, permissions)) { - Intent intent = new Intent(this, appPermission.class); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); - startActivity(intent); - } - } - else{ + stopService(new Intent(this,CustomService.class)); + Intent intent = new Intent(this, appPermission.class); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + startActivity(intent); + + } else { Intent serviceIntent = new Intent(this, CustomService.class); ContextCompat.startForegroundService(this, serviceIntent);