Android Tutorial Widget preview images

Hi All,

Below are my notes on getting a widget preview image to appear in the widget list. The preview image appears in place of the app icon (if used).

1) Create a png with the preview in it, I used 300 * 150 (size doesn't seem to matter but you want to get the aspect ratio done right)
2) Save the png into the \Objects\res\drawable of your app. Note that the filename MUST be lowercase with no symbols or the compiler will moan.
3) Mark the file as read only or Basic4Android will overwrite it

4) Now edit the widget info XML file in the \Objects\res\xml folder
5) Add in the tag as follows to the provider line
android:previewImage="@drawable/imagefilenamehere"
6) Change the imagefilenamehere text to your filename - make sure that you leave off the .png from the filename.
7) Mark this file as read only as well to ensure that it doesn't get overwritten.

Hope that helps someone!

Cheers,

Jon
 

bloxa69

Active Member
Licensed User
Longtime User
target SDK should be at least 11 for this to work

Hi All,

Below are my notes on getting a widget preview image to appear in the widget list. The preview image appears in place of the app icon (if used).

1) Create a png with the preview in it, I used 300 * 150 (size doesn't seem to matter but you want to get the aspect ratio done right)
2) Save the png into the \Objects\res\drawable of your app. Note that the filename MUST be lowercase with no symbols or the compiler will moan.
3) Mark the file as read only or Basic4Android will overwrite it

4) Now edit the widget info XML file in the \Objects\res\xml folder
5) Add in the tag as follows to the provider line
android:previewImage="@drawable/imagefilenamehere"
6) Change the imagefilenamehere text to your filename - make sure that you leave off the .png from the filename.
7) Mark this file as read only as well to ensure that it doesn't get overwritten.

Hope that helps someone!

Cheers,

Jon

Hey Jon, thank you, you saved my day (actually night). Anyway, I'd like to put my 2 cents in:

It didn't work for me until I targeted SDK 15 in my manifest. (I think it should be at least 11 to work.) I edited my manifest like this:

B4X:
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="15"/>
 

joneden

Active Member
Licensed User
Longtime User
You're welcome.

I'm targeting SDK 14 and it seems to work fine on them. I think that 14 is as low as you can go though.

The only issue that I still have is getting the widget height working properly - when I figure that I'll amend my original post :)
 

jvetterli

Member
Licensed User
Longtime User
I've just tried to insert preview widget images, but the compiler doesn't like it...

I've declared it as follows:
... android:initialLayout="@layout/widgetfourservice_layout" android:reviewImage="@drawable/picfour" android:updatePeriodMillis="3600000" ...

and get the following error message:

B4A version: 5.20
Parsing code. (0.01s)
Compiling code. (0.08s)
Compiling layouts code. (0.00s)
Generating R file. Error
res\xml\widgetfourservice_info.xml:2: error: No resource identifier found for attribute 'reviewImage' in package 'android'
res\xml\widgettwoservice_info.xml:2: error: No resource identifier found for attribute 'reviewImage' in package 'android'
 

jvetterli

Member
Licensed User
Longtime User
Thanks Erel, I did so and just tried the CreateResource method as well like this:

CreateResource(xml, widgettwoservice_info.xml,
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="140dp"
android:minHeight="120dp"
android:initialLayout="@layout/widgettwoservice_layout"
android:reviewImage="@drawable/pictwo"
android:updatePeriodMillis="3600000" />

But I still get the same error:

B4A version: 5.80
Parsing code. (0.03s)
Compiling code. (9.18s)
Compiling layouts code. (0.00s)
Generating R file. Error
res\xml\widgettwoservice_info.xml:2: error: No resource identifier found for attribute 'reviewImage' in package 'android'

The "pictwo.png" file is stored in \Objects\res\drawable of my app, size 300x150, just as described.
 

DonManfred

Expert
Licensed User
Longtime User
The "pictwo.png" file is stored in \Objects\res\drawable of my app, size 300x150, just as described.
Îs it still THERE??? I mean; Did you set readonly attribute to the file?
 

jvetterli

Member
Licensed User
Longtime User
Yes, that's the strange thing!
I did exactly as described, only switched the xml back to writeable when trying the CreateResource method
 

corwin42

Expert
Licensed User
Longtime User
The Identifier is called

B4X:
android:previewImage

and not reviewImage.

You should use code tags so that some character combinations don't get smileys. :p
 

jvetterli

Member
Licensed User
Longtime User
Thanks, stupid me, I was thinking about having to replace the :p from the sample with
B4X:
:p
but forgot at the end...
 
Top