mirror of
https://github.com/sudoxnym/nightd.git
synced 2026-05-17 11:09:07 +00:00
v1.2 - add BroadcastReceiver for bulletproof background triggering
This commit is contained in:
parent
2ebe1e174e
commit
05d444a5df
2 changed files with 36 additions and 2 deletions
|
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.sudox.nightd"
|
||||
android:versionCode="2"
|
||||
android:versionName="1.1">
|
||||
android:versionCode="3"
|
||||
android:versionName="1.2">
|
||||
|
||||
<uses-sdk android:minSdkVersion="24" android:targetSdkVersion="35" />
|
||||
|
||||
|
|
@ -38,6 +38,18 @@
|
|||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<receiver
|
||||
android:name=".NightdReceiver"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="com.sudox.nightd.TOGGLE" />
|
||||
<action android:name="com.sudox.nightd.ON" />
|
||||
<action android:name="com.sudox.nightd.OFF" />
|
||||
<action android:name="com.sudox.nightd.DIM" />
|
||||
<action android:name="com.sudox.nightd.BLACK" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<activity
|
||||
android:name=".NightdActivity"
|
||||
android:exported="true"
|
||||
|
|
|
|||
22
app/src/main/java/com/sudox/nightd/NightdReceiver.java
Normal file
22
app/src/main/java/com/sudox/nightd/NightdReceiver.java
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package com.sudox.nightd;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
|
||||
public class NightdReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Intent serviceIntent = new Intent(context, NightdService.class);
|
||||
String action = intent.getAction();
|
||||
if (action != null) {
|
||||
serviceIntent.setAction(action);
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
context.startForegroundService(serviceIntent);
|
||||
} else {
|
||||
context.startService(serviceIntent);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue