Attempt at fixing crashes
Этот коммит содержится в:
@@ -96,9 +96,9 @@ class MainFragment : PreferenceFragmentCompat(), OnSharedPreferenceChangeListene
|
||||
originalIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND)
|
||||
|
||||
val flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
PendingIntent.FLAG_MUTABLE
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
|
||||
} else {
|
||||
0
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
}
|
||||
alarmIntent = PendingIntent.getBroadcast(activity, 0, originalIntent, flags)
|
||||
|
||||
@@ -253,10 +253,12 @@ class MainFragment : PreferenceFragmentCompat(), OnSharedPreferenceChangeListene
|
||||
if (permission) {
|
||||
setPreferencesEnabled(false)
|
||||
ContextCompat.startForegroundService(requireContext(), Intent(activity, TrackingService::class.java))
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
|
||||
alarmManager.setInexactRepeating(
|
||||
AlarmManager.ELAPSED_REALTIME_WAKEUP,
|
||||
ALARM_MANAGER_INTERVAL.toLong(), ALARM_MANAGER_INTERVAL.toLong(), alarmIntent
|
||||
)
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
|
||||
&& ContextCompat.checkSelfPermission(requireContext(), Manifest.permission.ACCESS_BACKGROUND_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
@@ -275,7 +277,9 @@ class MainFragment : PreferenceFragmentCompat(), OnSharedPreferenceChangeListene
|
||||
}
|
||||
|
||||
private fun stopTrackingService() {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
|
||||
alarmManager.cancel(alarmIntent)
|
||||
}
|
||||
requireActivity().stopService(Intent(activity, TrackingService::class.java))
|
||||
setPreferencesEnabled(true)
|
||||
}
|
||||
|
||||
@@ -57,11 +57,10 @@ class TrackingService : Service() {
|
||||
|
||||
@SuppressLint("WakelockTimeout")
|
||||
override fun onCreate() {
|
||||
startForeground(NOTIFICATION_ID, createNotification(this))
|
||||
Log.i(TAG, "service create")
|
||||
|
||||
sendBroadcast(Intent(ACTION_STARTED))
|
||||
StatusActivity.addMessage(getString(R.string.status_service_create))
|
||||
startForeground(NOTIFICATION_ID, createNotification(this))
|
||||
|
||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
|
||||
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(MainFragment.KEY_WAKELOCK, true)) {
|
||||
@@ -89,10 +88,10 @@ class TrackingService : Service() {
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
stopForeground(true)
|
||||
Log.i(TAG, "service destroy")
|
||||
sendBroadcast(Intent(ACTION_STOPPED))
|
||||
StatusActivity.addMessage(getString(R.string.status_service_destroy))
|
||||
stopForeground(true)
|
||||
if (wakeLock?.isHeld == true) {
|
||||
wakeLock?.release()
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user