Android Question Error when using okhttpUtils2 v3.04 from receiver. Code Line OAuth2_AccessTokenAvailable.

DaOel

Member
Licensed User
Longtime User
I want to send Email Reminders in my app. I succesfully tried it from an activity.
Now I want to send it from a receiver in the background.
The 'ScheduledEmailReceiver' calls himself via

B4X:
Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)
'[...]
StartServiceAtExact(Me,Starter.NextCheck,True)
'[...]
Permission SCHEDULE_EXACT_ALARM is granted.


Later on I try to send an Email in the same context of Receiver_Receive

The Problem occurs at line
B4X:
Wait For OAuth2_AccessTokenAvailable (Success As Boolean, Token As String)

in this code block:

B4X:
Sub Send (msg As MailCreator)
    Starter.oauth2.GetAccessToken
    Wait For OAuth2_AccessTokenAvailable (Success As Boolean, Token As String)
    If Success = False Then
        Log("Error accessing account.")
        Return
    End If

Error:
B4X:
*** Receiver (scheduledemailreceiver) Receive  ***
** Activity (main) Pause, UserClosed = false **
java.lang.RuntimeException: Unable to start receiver b4a.fahrstundenPlaner.scheduledemailreceiver: java.lang.RuntimeException: anywheresoftware.b4a.B4AUncaughtException
    at android.app.ActivityThread.handleReceiver(ActivityThread.java:4852)
    at android.app.ActivityThread.access$1700(ActivityThread.java:315)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2297)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:226)
    at android.os.Looper.loop(Looper.java:313)
    at android.app.ActivityThread.main(ActivityThread.java:8751)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
Caused by: java.lang.RuntimeException: anywheresoftware.b4a.B4AUncaughtException
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:188)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at b4a.fahrstundenPlaner.scheduledemailreceiver.onReceive(scheduledemailreceiver.java:42)
    at android.app.ActivityThread.handleReceiver(ActivityThread.java:4843)
    ... 9 more
Caused by: anywheresoftware.b4a.B4AUncaughtException
    at anywheresoftware.b4a.Msgbox.debugWait(Msgbox.java:210)
    at anywheresoftware.b4a.debug.Debug.wait(Debug.java:217)
    at anywheresoftware.b4a.shell.Shell.debugPause(Shell.java:544)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:417)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    ... 12 more

Is it not possible to call OAuth2_AccessTokenAvailable from a receiver?
There were some posts about FirebaseMessaging and setting priority to 10. Is it possible to set the priority for OAuth2_AccessTokenAvailable as well?
 

MicroDrie

Well-Known Member
Licensed User
Longtime User
Now I want to send it from a receiver in the background.
Be aware that Google has tightened all kinds of security rules for Android. The philosophy behind this is that "dangerous" activities without the user's consent are no longer allowed. Activities that previously could simply be performed in the background are blocked by these new rules or require additional user permission.
Without stating how permission is obtained and a small example program, it is difficult to answer your question.
 
Upvote 0

DaOel

Member
Licensed User
Longtime User
thanks for looking into it.
understood, you can find an example in the attachment.

The Error I get is:
1703782533825.png

Things to change in order to reproduce:

1)

1703782589764.png


2)
Create Oauth2 cliend ID in Play Console - Android Credentials.

Insert CliendId here then:
1703782666105.png
 

Attachments

  • GmailFromService.zip
    61.2 KB · Views: 93
Last edited:
Upvote 0

DaOel

Member
Licensed User
Longtime User
It seems like the problem can be solved by introducing its own oauth2 object in the dedicated Receiver:

1703811920676.png



Is this a proper solution?
It works on my smartphone at least... I hope it will work on other smartphones as well.

I am a bit concenerned because of this:
And this related log:

1703812127529.png


There is also a small topic about related stuff from 2018:
 
Upvote 0

DaOel

Member
Licensed User
Longtime User
After everything worked nicely. I decided to upload the aab to Google PlayStore.
I was prepared that it did not work because Google re-signs the apps. So I downloaded the apk again and checked for the new SHA1 Finger print and updated my google api console credentials.

Now after uploading the production version of my app in google play store, I wanted to test whether it works. Unfortunatelly the app crashes.
(In a menu where I ask for oauth2 permissions, it redirects to the starting screen of my app, without listboxes to be populated.)

This behaviour is different to the behaviour I saw when using the B4A Bridge. What are my options now?

______

Just before the crash I see this screen in the webview again for a short period of time:
1703866472885.png


which reminds me of a problem I had with package-Naming:
My App also has upper Letters in the package name. I solved this by declaring a separate scheme with only lower letters. Did google manipulate the manifest or is it not possible to use a scheme at google playstore perhaps?
 
Last edited:
Upvote 0
Top