Use some new Android APIs
Этот коммит содержится в:
@@ -51,6 +51,8 @@ public class MainFragment extends PreferenceFragment implements OnSharedPreferen
|
|||||||
|
|
||||||
private static final String TAG = MainFragment.class.getSimpleName();
|
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_DEVICE = "id";
|
||||||
public static final String KEY_URL = "url";
|
public static final String KEY_URL = "url";
|
||||||
public static final String KEY_INTERVAL = "interval";
|
public static final String KEY_INTERVAL = "interval";
|
||||||
@@ -259,9 +261,9 @@ public class MainFragment extends PreferenceFragment implements OnSharedPreferen
|
|||||||
|
|
||||||
if (permission) {
|
if (permission) {
|
||||||
setPreferencesEnabled(false);
|
setPreferencesEnabled(false);
|
||||||
getActivity().startService(new Intent(getActivity(), TrackingService.class));
|
ContextCompat.startForegroundService(getActivity(), new Intent(getActivity(), TrackingService.class));
|
||||||
alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
|
alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
|
||||||
15000, 15000, alarmIntent);
|
ALARM_MANAGER_INTERVAL, ALARM_MANAGER_INTERVAL, alarmIntent);
|
||||||
} else {
|
} else {
|
||||||
sharedPreferences.edit().putBoolean(KEY_STATUS, false).apply();
|
sharedPreferences.edit().putBoolean(KEY_STATUS, false).apply();
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import android.location.Location;
|
|||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@@ -94,13 +95,13 @@ public class ShortcutActivity extends AppCompatActivity {
|
|||||||
switch (action) {
|
switch (action) {
|
||||||
case EXTRA_ACTION_START:
|
case EXTRA_ACTION_START:
|
||||||
PreferenceManager.getDefaultSharedPreferences(this)
|
PreferenceManager.getDefaultSharedPreferences(this)
|
||||||
.edit().putBoolean(MainFragment.KEY_STATUS, true).commit();
|
.edit().putBoolean(MainFragment.KEY_STATUS, true).apply();
|
||||||
startService(new Intent(this, TrackingService.class));
|
ContextCompat.startForegroundService(this, new Intent(this, TrackingService.class));
|
||||||
Toast.makeText(this, R.string.status_service_create, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.status_service_create, Toast.LENGTH_SHORT).show();
|
||||||
break;
|
break;
|
||||||
case EXTRA_ACTION_STOP:
|
case EXTRA_ACTION_STOP:
|
||||||
PreferenceManager.getDefaultSharedPreferences(this)
|
PreferenceManager.getDefaultSharedPreferences(this)
|
||||||
.edit().putBoolean(MainFragment.KEY_STATUS, false).commit();
|
.edit().putBoolean(MainFragment.KEY_STATUS, false).apply();
|
||||||
stopService(new Intent(this, TrackingService.class));
|
stopService(new Intent(this, TrackingService.class));
|
||||||
Toast.makeText(this, R.string.status_service_destroy, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.status_service_destroy, Toast.LENGTH_SHORT).show();
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import android.content.Intent;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
public class TrackingService extends Service {
|
public class TrackingService extends Service {
|
||||||
@@ -72,7 +73,7 @@ public class TrackingService extends Service {
|
|||||||
trackingController.start();
|
trackingController.start();
|
||||||
|
|
||||||
startForeground(NOTIFICATION_ID, createNotification(this));
|
startForeground(NOTIFICATION_ID, createNotification(this));
|
||||||
startService(new Intent(this, HideNotificationService.class));
|
ContextCompat.startForegroundService(this, new Intent(this, HideNotificationService.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user