Этот коммит содержится в:
Anton Tananaev
2017-08-30 15:34:45 +12:00
родитель 8d94b8d011
Коммит 77154a81af
3 изменённых файлов: 10 добавлений и 6 удалений
+4 -2
Просмотреть файл
@@ -51,6 +51,8 @@ public class MainFragment extends PreferenceFragment implements OnSharedPreferen
private static final String TAG = MainFragment.class.getSimpleName();
private static final int ALARM_MANAGER_INTERVAL = 15000;
public static final String KEY_DEVICE = "id";
public static final String KEY_URL = "url";
public static final String KEY_INTERVAL = "interval";
@@ -259,9 +261,9 @@ public class MainFragment extends PreferenceFragment implements OnSharedPreferen
if (permission) {
setPreferencesEnabled(false);
getActivity().startService(new Intent(getActivity(), TrackingService.class));
ContextCompat.startForegroundService(getActivity(), new Intent(getActivity(), TrackingService.class));
alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
15000, 15000, alarmIntent);
ALARM_MANAGER_INTERVAL, ALARM_MANAGER_INTERVAL, alarmIntent);
} else {
sharedPreferences.edit().putBoolean(KEY_STATUS, false).apply();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
+4 -3
Просмотреть файл
@@ -22,6 +22,7 @@ import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;
@@ -94,13 +95,13 @@ public class ShortcutActivity extends AppCompatActivity {
switch (action) {
case EXTRA_ACTION_START:
PreferenceManager.getDefaultSharedPreferences(this)
.edit().putBoolean(MainFragment.KEY_STATUS, true).commit();
startService(new Intent(this, TrackingService.class));
.edit().putBoolean(MainFragment.KEY_STATUS, true).apply();
ContextCompat.startForegroundService(this, new Intent(this, TrackingService.class));
Toast.makeText(this, R.string.status_service_create, Toast.LENGTH_SHORT).show();
break;
case EXTRA_ACTION_STOP:
PreferenceManager.getDefaultSharedPreferences(this)
.edit().putBoolean(MainFragment.KEY_STATUS, false).commit();
.edit().putBoolean(MainFragment.KEY_STATUS, false).apply();
stopService(new Intent(this, TrackingService.class));
Toast.makeText(this, R.string.status_service_destroy, Toast.LENGTH_SHORT).show();
break;
+2 -1
Просмотреть файл
@@ -24,6 +24,7 @@ import android.content.Intent;
import android.os.Build;
import android.os.IBinder;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;
public class TrackingService extends Service {
@@ -72,7 +73,7 @@ public class TrackingService extends Service {
trackingController.start();
startForeground(NOTIFICATION_ID, createNotification(this));
startService(new Intent(this, HideNotificationService.class));
ContextCompat.startForegroundService(this, new Intent(this, HideNotificationService.class));
}
@Override