Skip to content

Commit

Permalink
Status Widget (comments) traccar#429
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton-V-K committed Aug 24, 2023
1 parent 7687f0a commit 232fecc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/org/traccar/client/StatusWidget.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 - 2023 Anton Tananaev ([email protected]), Anton-V-K
* Copyright 2023 Anton-V-K
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -54,7 +54,7 @@ class StatusWidget : AppWidgetProvider() {
views.setImageViewResource(R.id.image_enabled, if (enabled) R.mipmap.ic_start else R.mipmap.ic_stop)

val intent = Intent(context, MainActivity::class.java)
val clickIntent = PendingIntent.getActivity(context,0, intent,
val clickIntent = PendingIntent.getActivity(context, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
views.setOnClickPendingIntent(R.id.image_enabled, clickIntent)

Expand Down
7 changes: 3 additions & 4 deletions app/src/main/java/org/traccar/client/TrackingService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ class TrackingService : Service() {
override fun onCreate() {
startForeground(NOTIFICATION_ID, createNotification(this))
Log.i(TAG, "service create")
// Explicit package name is required here for manifest-declared receiver of the status widget
// Refer to https://developer.android.com/guide/components/broadcasts#manifest-declared-receivers
sendBroadcast(Intent(ACTION_STARTED).setPackage(packageName))
StatusActivity.addMessage(getString(R.string.status_service_create))

Expand Down Expand Up @@ -92,8 +90,6 @@ class TrackingService : Service() {
override fun onDestroy() {
stopForeground(true)
Log.i(TAG, "service destroy")
// Explicit package name is required here for manifest-declared receiver of the status widget
// Refer to https://developer.android.com/guide/components/broadcasts#manifest-declared-receivers
sendBroadcast(Intent(ACTION_STOPPED).setPackage(packageName))
StatusActivity.addMessage(getString(R.string.status_service_destroy))
if (wakeLock?.isHeld == true) {
Expand All @@ -104,6 +100,9 @@ class TrackingService : Service() {

companion object {

// Explicit package name should be specified when broadcasting START/STOP notifications -
// it is required for manifest-declared receiver of the status widget (when running on Android 8+).
// Refer to https://developer.android.com/guide/components/broadcasts#manifest-declared-receivers
const val ACTION_STARTED = "org.traccar.action.SERVICE_STARTED"
const val ACTION_STOPPED = "org.traccar.action.SERVICE_STOPPED"
private val TAG = TrackingService::class.java.simpleName
Expand Down

0 comments on commit 232fecc

Please sign in to comment.