I can't get my BroadcastReciever() to work for DATE_CHANGED, but works just fine for TIMEZONE_CHANGED.
class DateChangeReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
Log.d("my broadcast","works")
if (intent.action == Intent.ACTION_DATE_CHANGED ||
intent.action == Intent.ACTION_TIMEZONE_CHANGED) {
var netUtils = NetUtils(context)
netUtils.mainStack()
}
}
}
Here is my Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<application
android:allowBackup="true"
android:icon="@drawable/castle"
android:roundIcon="@drawable/castle"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>
</activity>
<receiver android:name=".DateChangeReceiver">
<intent-filter>
<action android:name="android.intent.action.DATE_CHANGED"/>
<action android:name="android.intent.action.TIMEZONE_CHANGED"/>
</intent-filter>
</receiver>
</application>
</manifest>
Here is my function in my main activity:
fun keepAlive() {
//KEEP RUNNING IN BACKGROUND TO UPDATE WALLPAPER AT CHANGE OF DAY
val component = ComponentName(this@MainActivity, DateChangeReceiver::class.java)
packageManager.setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP)
Log.d("KEEPALIVE FUN","works")
}
keepAlive()
I get nothing in logcat when I change my date manually or if I set the time to 11:59 and wait a minute.
A couple of errors I do have in logcat that show up before I added the Reciever are:
2019-03-05 11:48:01.884 29176-29202/com.test E/libc: Access denied finding property "vendor.debug.egl.profiler"
2019-03-05 11:48:07.616 29176-29234/com.test E/libc: Access denied finding property "ro.vendor.graphics.memory"
2019-03-05 11:48:07.665 29176-29234/com.test E/libc: Access denied finding property "vendor.gralloc.enable_ahardware_buffer"
Is it possible these are effecting my BroadcastReciever? I've tested this on 3 devices so far.