Skip to content

Commit

Permalink
Merge pull request #48 from WildOrangutan
Browse files Browse the repository at this point in the history
Fixed notification actions on Oreo devices
  • Loading branch information
mathisdt committed Oct 28, 2018
2 parents 09ad3c9 + c22af2d commit 797b71a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
4 changes: 0 additions & 4 deletions app/src/main/AndroidManifest.xml
Expand Up @@ -46,10 +46,6 @@
android:name="ThirdPartyReceiver"
android:exported="true"
tools:ignore="ExportedReceiver" >
<intent-filter>
<action android:name="org.zephyrsoft.trackworktime.ClockIn" />
<action android:name="org.zephyrsoft.trackworktime.ClockOut" />
</intent-filter>
</receiver>

<service
Expand Down
30 changes: 29 additions & 1 deletion app/src/main/java/org/zephyrsoft/trackworktime/Basics.java
Expand Up @@ -25,6 +25,7 @@
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.location.Location;
Expand Down Expand Up @@ -82,6 +83,7 @@ public class Basics extends BroadcastReceiver {
private ExternalNotificationManager externalNotificationManager = null;
private NotificationChannel notificationChannel = null;
private NotificationChannel serviceNotificationChannel = null;
private ThirdPartyReceiver thirdPartyReceiver;

private static Basics instance = null;

Expand Down Expand Up @@ -116,7 +118,6 @@ public static Basics getOrCreateInstance(Context androidContext) {
public void onReceive(Context androidContext, Intent intent) {
// always only use the one instance
instance.receivedIntent(androidContext);

}

/**
Expand Down Expand Up @@ -146,6 +147,33 @@ private void init() {
.writingThread(threadToObserve, 1)
.activate();
Logger.info("logger initialized - writing thread observes \"{}\"", threadToObserve);

registerThirdPartyReceiver();
}

private void registerThirdPartyReceiver() {
if(thirdPartyReceiver != null) {
Logger.warn(ThirdPartyReceiver.class.getSimpleName() + " already registered, skipping.");
return;
}

thirdPartyReceiver = new ThirdPartyReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("org.zephyrsoft.trackworktime.ClockIn");
intentFilter.addAction("org.zephyrsoft.trackworktime.ClockOut");
context.registerReceiver(thirdPartyReceiver, intentFilter);
Logger.debug("Registered " + ThirdPartyReceiver.class.getSimpleName());
}

public void unregisterThirdPartyReceiver() {
if(thirdPartyReceiver == null) {
Logger.warn(ThirdPartyReceiver.class.getSimpleName() + " not registered, skipping.");
return;
}

context.unregisterReceiver(thirdPartyReceiver);
thirdPartyReceiver = null;
Logger.debug("Unregistered " + ThirdPartyReceiver.class.getSimpleName());
}

public File getCurrentLogFile() {
Expand Down
Expand Up @@ -112,6 +112,7 @@ public void onCreate() {
public void onTerminate() {
Logger.info("terminating application");
Basics.getOrCreateInstance(getApplicationContext()).getDao().close();
Basics.getInstance().unregisterThirdPartyReceiver();
super.onTerminate();
}

Expand Down

0 comments on commit 797b71a

Please sign in to comment.