Android Question Widget with API 26

Cebuvi

Active Member
Licensed User
Longtime User
Hello

I have verified that with API 26 the widgets of my application do not update and stop responding.

Will this be solved with the new version of B4A?

Thanks.

César
 

DavideV

Active Member
Licensed User
Longtime User
After compiling with B4A 8.0 it now works without making any changes to the original code.

I suppose it does not require any change from the old tutorials

Star-Dust,
the service that handles the widget requires only 1 line as Erel wrote
Service.StopAutomaticForeground

Widgets:
B4X:
Sub Service_Start (StartingIntent As Intent)
   rv.HandleWidgetEvents(StartingIntent)
   Sleep(0)
   Service.StopAutomaticForeground
End Sub
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Honestly I did not make this change. But at the moment it seems to work perfectly.

This is my code:
B4X:
Sub Service_Start (StartingIntent As Intent)
    If rv.HandleWidgetEvents(StartingIntent) Then Return
End Sub

But i call StopService(Me)
B4X:
Sub Widg_Disabled
    StopService("")
End Sub


@Erel wrote
You need to do one thing which is to stop the automatic foreground mode when the service completed its task.
This can be done in two ways:

1. Call Service.StopAutomaticForeground. This will stop the automatic foreground mode if the service was in that mode. Otherwise it will not do anything.
It is safe to call it multiple times. The service will not be immediately destroyed.

2. Call StopService(Me).
 
Last edited:
Upvote 0

DavideV

Active Member
Licensed User
Longtime User
Honestly I did not make this change. But at the moment it seems to work perfectly.

This is my code:
B4X:
Sub Service_Start (StartingIntent As Intent)
    If rv.HandleWidgetEvents(StartingIntent) Then Return
End Sub

Are you sure the Notification icon of your widget is not displayed on the top left of your device's display?

I had the notificationicon due to the missing line, the icon has gone after adding :
Service.StopAutomaticForeground

also i changed the
If rv.HandleWidgetEvents(StartingIntent) Then Return
into
rv.HandleWidgetEvents(StartingIntent)

otherwise the Service.StopAutomaticForeground could not be executed all the times


But i don't want to bother you, if it works for you it should be OK ;)

Edit, ok i see you edited your post a minutes ago, it seems ok !
 
Upvote 0

Marcus Araujo

Member
Licensed User
Longtime User
I am having the same issue if I set android:targetSdkVersion="26". For targetSdkVersion 24 it does not give an error.

The service I am using is FirebaseMessaging, to handle notifications.
No luck with StopAutomaticForeground, though.
 
Upvote 0

Cebuvi

Active Member
Licensed User
Longtime User
Hi
my app has a widget that when you click on the location icon, the location is updated.

If I compile it with B4A 8.0 without adding Service.StopAutomaticForeground, everything works correctly but the notification icon remains permanent.
When I add Service.StopAutomaticForeground, clicking on the location icon causes this error and the app stops.

solarw4x2_flp42p_connectionsuccess (java line: 211)
java.lang.IllegalStateException: GoogleApiClient is not connected yet.
at com.google.android.gms.common.api.internal.zzao.zze(Unknown Source:4)
at com.google.android.gms.common.api.internal.zzbi.zze(Unknown Source:5)
at com.google.android.gms.common.api.internal.zzba.zze(Unknown Source:147)
at com.google.android.gms.internal.zzceb.requestLocationUpdates(Unknown Source:14)
at uk.co.martinpearman.b4a.fusedlocationprovider.FusedLocationProviderWrapper.RequestLocationUpdates(FusedLocationProviderWrapper.java:202)
at b4a.example.solarw4x2._flp42p_connectionsuccess(solarw4x2.java:211)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at uk.co.martinpearman.b4a.fusedlocationprovider.FusedLocationProvider.onConnected(FusedLocationProvider.java:64)
at com.google.android.gms.common.internal.zzae.zzk(Unknown Source:108)
at com.google.android.gms.common.api.internal.zzba.zzj(Unknown Source:22)
at com.google.android.gms.common.api.internal.zzao.zzaie(Unknown Source:89)
at com.google.android.gms.common.api.internal.zzao.onConnected(Unknown Source:21)
at com.google.android.gms.common.api.internal.zzbi.onConnected(Unknown Source:7)
at com.google.android.gms.common.api.internal.zzt.onConnected(Unknown Source:5)
at com.google.android.gms.common.internal.zzac.onConnected(Unknown Source:2)
at com.google.android.gms.common.internal.zzn.zzakr(Unknown Source:143)
at com.google.android.gms.common.internal.zze.zzw(Unknown Source:47)
at com.google.android.gms.common.internal.zzi.zzaks(Unknown Source:54)
at com.google.android.gms.common.internal.zzh.handleMessage(Unknown Source:275)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
** Receiver (solarw4x2) OnReceive **
*** Service (starter) Create ***
** Service (starter) Start **

With previous versions everything worked perfectly

Send a test file

Thanks.
 

Attachments

  • Widget_API26.zip
    20.7 KB · Views: 312
  • 2018-03-22_170931.jpg
    2018-03-22_170931.jpg
    28.6 KB · Views: 311
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
With previous versions everything worked perfectly
How can it be if widgets didn't work at all on Android 8 devices in previous versions?

There are several mistakes in Service_Start:
1. You are calling HandleWidgetrsEvents twice.
2. You are not calling StopAutomaticForeground in the very first case.

The error you are encountering is most probably related to a change in Android 8. It is explained this tutorial (at the bottom): https://www.b4x.com/android/forum/threads/90546/#content

This causes your code to initialize FLP42P multiple times. Only initialize it if IsInitialized returns false.
 
Upvote 0

Cebuvi

Active Member
Licensed User
Longtime User
Thank you very much Erel, making the corrections that you proposed, everything works correctly.
 
Upvote 0
Top