6

I'm creating an Android Widget and are trying to receive the USER_PRESENT intent that I have registered in my AndroidManifest.xml. When the user unlocks their phone the widget should fetch and update itself with weather information I fetch from a backend. But i'm not receiving it on my Android 8 device. From what I read this is no longer supported?

I do it like this:

<receiver android:name=".AppWidgetProvider" android:label="@string/widget_name_4_2">
  <intent-filter>
    <action android:name="android.intent.action.USER_PRESENT" />
  </intent-filter>
  <meta-data
    android:name="android.appwidget.provider"
    android:resource="@xml/appwidget_info" />
</receiver>

And in my AppWidgetProvider

@Override
public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);
    Log.w("log", "onReceive " + intent.getAction());
}

What is the alternatives to catch this intent? Foreground service? Something else? Is it even possible now days?

Martin
  • 195
  • 1
  • 12
  • Those implicit broadcasts registered in the manifest are not delivered any more (with a few exceptions that can be found in the android docs). You need to register for broadcasts programmatically, but there's also restrictions on this (e.g. you cannot do it from a broadcastreceiver context, need to use context.getApplicationContext()). I got a similar problem and I'm still trying to figure out a solution. Will let you know when I did. – joe1806772 Oct 10 '18 at 15:12
  • I also tried that and then recevied the broadcast, but the solution feels very fragile. I had problems to unregister it as well. I will continue the search as well :) – Martin Oct 12 '18 at 19:47
  • 2
    did you find anything as a solution? – Mustafa Güven Oct 01 '19 at 07:49
  • Any solution??? – Ranjan Aug 28 '20 at 09:16
  • No solution sorry and i've left the project due to new work :( – Martin Aug 29 '20 at 11:24

0 Answers0