Android Question Personalise an app by loading a bitmap

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All

I have a small App that I want the end user to be able to personalise [load a bitmap/photo] and then pass on the APK to others. This should be easy but as a newbie I am lost for a starting point. All searches take me to loading bitmaps at the source code stage.

Can someone please point me to an example, I am sure this has been done many times before.

Regards Roger
 

Roger Daley

Well-Known Member
Licensed User
Longtime User
Thanks NJDude

I will cancel Plan "A".

As a compromise [plan "B"] can you have the APK automatically load in an external bitmap file at start up and display it on part of the screen? [As in the manner of a picture viewer]. This way the bitmap could be changed if the file name was the same.
This would of course mean that the bitmap file would always have to accompany the APK, awkward but possible.
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
I guess I didn't explain myself clearly for plan "B".
I understand that you can't add to an APK but an APP can display bitmaps. IE B4A equivalents of Gallery, QuickPic etc.

What I am asking is:
i can I have my APP [not a picture viewer] display an image file on part of the screen and overlaying the APP?
ii can I do this by code at start up?

This question/answer suggests that I can but I lack the knowledge to fully understand/implement it for my purposes.
http://www.b4x.com/android/forum/th...terminated-for-specific-file-image-jpg.34255/

Regards Roger
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
You can load and display any image you like in your app. Of course you can show it on any position of the screen you like to.

So explain what you want to do exactly. I will post an eample for you.

f.e.

1. Load an image
2. show it @ position x,y
 
Upvote 0

udg

Expert
Licensed User
Longtime User
As I understand it, Roger would like to deliver an app that sports a user-modifiable image in it.
A 3-steps process:
1. Original app has image0 in its folder dir
2. User A launches the app, image0 is copied to a DefaultDir and userA changes it to image1
3. User A "sends" the app to a friend with image1 instead of the original image0

As NJDude clearly posted, that last third step couldn't be accomplished.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
will you hand it over to user1 (the maintainer) by email or something?

if it arrives on a windows/linux/max machine first then he can change the image inside the APK with tools like total commander, 7zip file manager etc.

and then send the apk to the right person.

or you can write a simple front end to simplify this process if the maintainer is of the "computer dumb/noob" type ;)
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
You can load and display any image you like in your app. Of course you can show it on any position of the screen you like to.

So explain what you want to do exactly. I will post an eample for you.

f.e.

1. Load an image
2. show it @ position x,y


Klaus/Erel

Attached are two files, a dummy example and a bitmap.

Scenario:
i I send the APK [no source code] of "example" to Erel he is so impressed he wants to personalise the APP.
ii Erel produces his own bitmap [mybanner.png] mybanner.png and saves it to a designated location on the device.
iii Erel starts the APP and code in "Sub Activity_Create(FirstTime As Boolean)" looks for mybanner.png in the designated folder and if found displays mybanner.png at X,Y.

Generically [pretend code] the code could look something like this:

If Exists "pathname/mybanner.png" then
imgbanner.sendtoback
display(pathname/mybanner.png".X,Y)
Else
imgbanner.bringtofront
End If

My problem is how to move from generic code to real B4A code, which folder, how to scale "mybanner.png" etc.

Regards Roger
 

Attachments

  • example.zip
    78.5 KB · Views: 136
Last edited:
Upvote 0

sorex

Expert
Licensed User
Longtime User
you better use imgbanner.visible=false because when the back banner is bigger you will still see parts of it.
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
will you hand it over to user1 (the maintainer) by email or something?

if it arrives on a windows/linux/max machine first then he can change the image inside the APK with tools like total commander, 7zip file manager etc.

and then send the apk to the right person.

or you can write a simple front end to simplify this process if the maintainer is of the "computer dumb/noob" type ;)


Sorex,

I have to assume the APK could end up with someone who thinks "source code" means "ketchup recipe`"
Even less knowlegible than myself.

Regards Roger
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
another way is letting the end users enter some kind of key (A8G0P8C70 or something) the first time they start the app.

the app checks with a webservice if the key is valid.

if it is it returns the url to the right images that's been uploaded by the maintainer.

then you just need some php backend to controll everything.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi Roger,
so you don't need point 3 as outlined in post #8 above, right?
To let each user (eventually) load a personalized image at app's start you could do something:
B4X:
'in Sub Activity_Create
If not File.Exists(File.DirDefaultExternal,"mybanner.png") Then File.Copy(File.DirAssets,"defaultbanner.png",File.DirDefaultExternal,"mybanner.png")
then proceed to load "mybanner.png" in the imagebanner object as appropriate.

Following the above scheme, you deploy your app with a default banner image stored in the Files tab in the IDE.
When the user starts your app for the first time, that file is copied in the app's default dir and named "mybanner".
You simply display this as the only possible banner.
Then each user has the ability to change that file (mybanner.png) if so inclined and your code stays unchanged since on next run it will find a "mybanner.png" file and load it (it could be the defaullt one, if the user didn't change it, or a user supplied one if it was substituted).

Before loading the image you should process it in order to preserve any constraints (e.g. file type, colors, dimensions..) your app is bound to.

Umberto
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
Just a final post to confirm Umberto's solution did work and some sample code/s in case another newbie comes looking for a way to provide the end-user a customisable APP. I have chosen to use the "Download" folder for the end user files as it easy for non-technical users to access. IE Save an email attachment.

USER SUPPLIED BMP FOR AN IMAGEVIEW
Dim imgbanner AS ImageView
If File.Exists(File.DirRootExternal & "/Download/","mybanner.png") Then
imgbanner.Bitmap = LoadBitmap(File.DirRootExternal & "/Download/","mybanner.png")
Else
imgbanner.Bitmap = LoadBitmap(File.DirAssets,"defaultbanner.png")
End If


USER SUPPLIED BMP FOR A BUTTON
Dim A0 AS Button

If File.Exists(File.DirRootExternal & "/Download/","mybutton1.png") Then
A0.SetBackgroundImage(LoadBitmap(File.DirRootExternal & "/Download/","mybutton1.png"))
Else
A0.SetBackgroundImage(LoadBitmap(File.DirAssets,"defaultbtn.png"))
End If


USER SUPPLIED TEXT FOR A STRING
Dim Welcome1 AS String

If File.Exists(File.DirRootExternal & "/Download/","mytext.txt") Then
Welcome1 = File.ReadString(File.DirRootExternal & "/Download/","mytext.txt")
Else
Welcome1 = File.ReadString(File.DirAssets,"defaulttext.txt")
End If


USER SUPPLIED MP3
Dim Fanfare As MediaPlayer

If File.Exists(File.DirRootExternal & "/Download/","myfanfare.mp3") Then
Fanfare.Initialize
Fanfare.Load(File.DirRootExternal & "/Download/","myfanfare.mp3")
Else
Fanfare.Initialize
Fanfare.Load(File.DirRootExternal & "/Download/","defaultfanfare.mp3")
End If


Hopefully this is useful to someone.

My thanks again to Umberto et al.
Regards Roger
 
Last edited:
Upvote 0
Top