Improve BG

This commit is contained in:
Mieszko Wrzeszczyński 2018-11-28 09:21:41 +01:00
parent 1154366024
commit a744c4d783
4 changed files with 12 additions and 38 deletions

View File

@ -8,7 +8,7 @@ android {
} }
defaultConfig { defaultConfig {
applicationId "com.uam.wmi.findmytutor" applicationId "com.uam.wmi.findmytutor"
minSdkVersion 22 minSdkVersion 23
targetSdkVersion 27 targetSdkVersion 27
versionCode 5 versionCode 5
versionName "0.9.0-alpha" versionName "0.9.0-alpha"

View File

@ -15,6 +15,8 @@
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /> <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-feature android:name="android.hardware.location.gps" /> <uses-feature android:name="android.hardware.location.gps" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<application <application
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"

View File

@ -4,11 +4,15 @@ import android.Manifest;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Fragment; import android.app.Fragment;
import android.app.FragmentTransaction; import android.app.FragmentTransaction;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.PowerManager;
import android.provider.Settings;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView; import android.support.design.widget.BottomNavigationView;
import android.support.design.widget.NavigationView; import android.support.design.widget.NavigationView;
@ -37,6 +41,7 @@ import com.uam.wmi.findmytutor.utils.RxSearchObservable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
@ -54,7 +59,7 @@ public abstract class BaseActivity
private final static int REQUEST_CODE_ASK_PERMISSIONS = 1; private final static int REQUEST_CODE_ASK_PERMISSIONS = 1;
private static final String[] REQUIRED_SDK_PERMISSIONS = new String[]{ private static final String[] REQUIRED_SDK_PERMISSIONS = new String[]{
Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_LOCATION_EXTRA_COMMANDS, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_LOCATION_EXTRA_COMMANDS,
Manifest.permission.WAKE_LOCK}; Manifest.permission.WAKE_LOCK, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS};
public DrawerLayout drawerLayout; public DrawerLayout drawerLayout;
protected BottomNavigationView navigationView; protected BottomNavigationView navigationView;
protected NavigationView drawerNavigationView; protected NavigationView drawerNavigationView;
@ -204,7 +209,6 @@ public abstract class BaseActivity
public void handleBackgroundTaskLifeCycle() { public void handleBackgroundTaskLifeCycle() {
Boolean shouldServiceRun = PrefUtils.isEnableSharingLocalization(getApplicationContext()); Boolean shouldServiceRun = PrefUtils.isEnableSharingLocalization(getApplicationContext());
Log.e("shouldRUN", String.valueOf(shouldServiceRun));
if (shouldServiceRun) { if (shouldServiceRun) {
startBackgroundLocalizationTask(); startBackgroundLocalizationTask();

View File

@ -2,9 +2,6 @@ package com.uam.wmi.findmytutor.service;
import android.Manifest; import android.Manifest;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.IntentService;
import android.app.KeyguardManager;
import android.app.Notification; import android.app.Notification;
import android.app.NotificationChannel; import android.app.NotificationChannel;
import android.app.NotificationManager; import android.app.NotificationManager;
@ -21,13 +18,10 @@ import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.HandlerThread; import android.os.HandlerThread;
import android.os.IBinder; import android.os.IBinder;
import android.os.PowerManager;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi; import android.support.annotation.RequiresApi;
import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityCompat;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
import android.util.Log; import android.util.Log;
import android.widget.Toast;
import com.google.android.gms.location.FusedLocationProviderClient; import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices; import com.google.android.gms.location.LocationServices;
@ -44,8 +38,6 @@ import com.uam.wmi.findmytutor.utils.mapUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
@ -64,11 +56,12 @@ public class BackgroundLocalizationService extends Service {
private static final String TAG = "MyLocationService"; private static final String TAG = "MyLocationService";
private static final int LOCATION_INTERVAL = 1000; private static final int LOCATION_INTERVAL = 1000;
private static final float LOCATION_DISTANCE = 5f; private static final float LOCATION_DISTANCE = 5f;
public static String str_receiver = "background.location.broadcast";
public static Runnable runnable = null;
private static long notify_interval = 10000; private static long notify_interval = 10000;
public Handler handler = null;
Location mLastLocation; Location mLastLocation;
Boolean stopService = false; Boolean stopService = false;
Intent intent;
public static String str_receiver = "background.location.broadcast";
ArrayList<String> providers = new ArrayList<String>(); ArrayList<String> providers = new ArrayList<String>();
LocationListener[] mLocationListeners; LocationListener[] mLocationListeners;
@ -78,12 +71,6 @@ public class BackgroundLocalizationService extends Service {
private Runnable mStatusChecker; private Runnable mStatusChecker;
private FusedLocationProviderClient mFusedLocationClient; private FusedLocationProviderClient mFusedLocationClient;
PowerManager pm;
PowerManager.WakeLock wl;
public Handler handler = null;
public static Runnable runnable = null;
public BackgroundLocalizationService() { public BackgroundLocalizationService() {
providers.add(LocationManager.GPS_PROVIDER); providers.add(LocationManager.GPS_PROVIDER);
providers.add(LocationManager.NETWORK_PROVIDER); providers.add(LocationManager.NETWORK_PROVIDER);
@ -94,7 +81,6 @@ public class BackgroundLocalizationService extends Service {
new LocationListener(LocationManager.NETWORK_PROVIDER), new LocationListener(LocationManager.NETWORK_PROVIDER),
new LocationListener(LocationManager.PASSIVE_PROVIDER) new LocationListener(LocationManager.PASSIVE_PROVIDER)
}; };
} }
@Override @Override
@ -103,24 +89,13 @@ public class BackgroundLocalizationService extends Service {
} }
@SuppressLint({"MissingPermission", "InvalidWakeLockTag"}) @SuppressLint({"MissingPermission", "InvalidWakeLockTag"})
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
Log.e(TAG, "onStartCommand"); Log.e(TAG, "onStartCommand");
super.onStartCommand(intent, flags, startId); super.onStartCommand(intent, flags, startId);
try {
pm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakeLock");
wl.acquire();
wl.release();
} catch (Exception ignored) {
}
if (intent != null) { if (intent != null) {
stopService = intent.getBooleanExtra("request_stop", false); stopService = intent.getBooleanExtra("request_stop", false);
} }
@ -138,10 +113,6 @@ public class BackgroundLocalizationService extends Service {
@Override @Override
public void onCreate() { public void onCreate() {
// when you done
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
startMyOwnForeground(); startMyOwnForeground();
else { else {
@ -186,9 +157,6 @@ public class BackgroundLocalizationService extends Service {
handler.postDelayed(runnable, 15000); handler.postDelayed(runnable, 15000);
} }
} }