Share My Creation B4A Quotes Widget - in B4XPages

I am very very happy today.
I have been able to complete the app I was trying for last few months.

My goal was to,
make a widget app
make it in B4XPages
it would download html from url
parse the html and extract text
show the text in the widget
would run every hour or so

I have achieved in all my goals, thanks to B4X.

Taking cue from Saif, I start by thanking @Erel.

Not only because Erel made B4X but also it is Erel's widget sample code which I took as inspiration.
It is a Quotes Widget, very old and uses old libraries which give errors now, as discussed here,

Below are the screen-shots of my "B4A Quotes Widget" app.

p4.pngp2.png p3.png p1.png

In main screen you enter the url (taken one from original sample of Erel). Check it with 'Load Quote' button. 'Save & Close' the app.
In widget touch the 'play' button and it will load quote from the url and display. There are 4 quotes and widget displays them one after another.
Widget will auto load quote every hour.
A clock is also running to show that the widget is active. May be it will stop in higher Android version.
Widget need internet connection and will show failed if not found.

I have checked it in Android 5 Lenevo only but would like feedback in Android 10+, if any member have one.

I have attached the project source codes and request members to play with it. If one can enhance it, upload the code here for benefit of other members.

I have plan to add radio buttons for urls as given in original sample of Erel, to select. So that user can just select the one required. Also to have touch event in widget to open the main activity.

Regards,

Anand

version 2 : manifest correction for Android 10+ on 06 May 2021
version 1 : initial release on 06 May 2021
 

Attachments

  • B4A_Quotes_Widget.zip
    359.4 KB · Views: 105
Last edited:

José J. Aguilar

Expert
Licensed User
Hi Anand:

Thanks for sharing.
Testing on a Samsung A10 with Android 10.
I get the CLEARTEXT error. (The second part of the error is due running the app in debug mode, widgets app must be tested in RELEASE mode)

So, you have to add to your project's manifest:
B4X:
' 28 - Non-ssl (non-https) communication is not permitted by default.
' It can be enabled in B4A v9+ by adding this line to the manifest editor:
CreateResourceFromFile(Macro, Core.NetworkClearText)
As noted in the android.jar / targetSdkVersion / minSdkVersion tutorial, and then it works great¡¡

Error logs:
Registro conectado a:  samsung SM-A105FN
--------- beginning of main
Copying updated assets files (6)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
ResponseError. Reason: java.net.UnknownServiceException: CLEARTEXT communication to feeds.feedburner.com not permitted by network security policy, Response:
** Activity (main) Pause event (activity is not paused). **
** Receiver (widgetservice) OnReceive **
*** Service (widgetservice) Create ***
Error occurred on line: 23 (WidgetService)
java.io.FileNotFoundException: l1.bal
    at android.content.res.AssetManager.nativeOpenAsset(Native Method)
    at android.content.res.AssetManager.open(AssetManager.java:875)
    at android.content.res.AssetManager.open(AssetManager.java:852)
    at anywheresoftware.b4a.objects.RemoteViewsWrapper.createRemoteViews(RemoteViewsWrapper.java:39)
    at b4a.quotes_widget.widgetservice._service_create(widgetservice.java:610)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at b4a.quotes_widget.widgetservice.onCreate(widgetservice.java:56)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:4281)
    at android.app.ActivityThread.access$1500(ActivityThread.java:270)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2067)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:237)
    at android.app.ActivityThread.main(ActivityThread.java:7948)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)
** Service (widgetservice) Start **
 
Top