Android Question How to load a picture from my GoogleDrive to ImageView in B4A

Antoine EGO

Member
Hello,
I have an email account on gmail : [email protected] with a Password
I want to store my images in a folder in GoogleDrive which is offered by my email account.
How to load (for example: Arrow.jpg from folder MyImages) from my GoogleDrive to ImageView in B4A ?

MyDrive_MyImages.jpg


In Your Booklet B4XBasicLanguageV1_9.pdf page#63 I found this code to load an image from your site:

To load a picture from internet to ImageView:
Sub Globals
    Private ImageView1 As ImageView
    Private btnLoadImage As Button
End Sub

Sub btnLoadImage_Click
    Dim MyLink As String
    MyLink="https://www.b4x.com/images3/android.png"
    DownloadImage(MyLink, ImageView1)
End Sub

'Good example. Use:
Sub DownloadImage(Link As String, iv As ImageView)
    Dim job As HttpJob
    job.Initialize("", Me) 'note that the name parameter is no longer needed.
    job.Download(Link)
    Wait For (job) JobDone(job As HttpJob)
    If job.Success Then
        iv.Bitmap = job.GetBitmap
    End If
    job.Release
End Sub
 
Last edited:

Antoine EGO

Member
I got the link of file as below
MyDrive_MyImages-1.jpg


Then I changed the Privacy to be public as below:

MyDrive_MyImages-2.jpg


Then I clicked on Copy link and paste it in my code in line 8:

B4X:
MyLink="https://drive.google.com/file/d/11RpsORWOMJR2C_OGEqxkmUE6cRtrQCQY/view?usp=sharing"

When the code runs ,it gives me this error log:

httpjob_getbitmap (java line: 226)
java.lang.RuntimeException: Error loading bitmap.
at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Initialize2(CanvasWrapper.java:539)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Initialize(CanvasWrapper.java:517)
at anywheresoftware.b4a.keywords.Common.LoadBitmap(Common.java:1342)
at b4a.MyGoogleDrive.httpjob._getbitmap(httpjob.java:226)
at b4a.MyGoogleDrive.main$ResumableSub_DownloadImage.resume(main.java:480)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:207)
at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1178)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6198)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:891)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:781)

BUT if I past it in my browser , I get the image!

Please
Please Help!
 
Upvote 0

Antoine EGO

Member
when I add this line:
B4X:
lblResult.text=Job.GetString
It shows:

<!DOCTYPE html><html><head><meta name="google" content="notranslate"><meta http-equiv="X-UA-Compatible" content="IE=edge;"><style>@font-face{font-family:'Roboto';font-style:italic;font-weight:400;src:url(//fonts.gstatic.com/s/roboto/v18/KFOkCnqEu92Fr1Mu51xIIzc.ttf)format('truetype');}@font-face{font-family:'Roboto';font-style:normal;font-weight:300;src:url(//fonts.gstatic.com/s/roboto/v18/KFOlCnqEu92Fr1MmSU5fBBc9.ttf)format('truetype');}@font-face{font-family:'Roboto';font-style:normal;font-weight:400;src:url(//fonts.gstatic.com/s/roboto/v18/KFOmCnqEu92Fr1Mu4mxP.ttf)format('truetype');}@font-face{font-family:'Roboto';font-style:normal;font-weight:700;src:url(//fonts.gstatic.com/s/roboto/v18/KFOlCnqEu92Fr1MmWUlfBBc9.ttf)format('truetype');}</style><meta name="referrer" content="origin"><title>Arrow.jpg - Google Drive</title><meta property="og:title" content="Arrow.jpg"><meta property="og:type" content="article"><meta property="og:site_name" content="Google Docs"><meta property="og:url" content=""><meta property="og:image" content="https://lh6.googleusercontent.com/F...RabDwSrBU57aOMKl_Casi-J9-OAU4JqQ=w1200-h630-p"><meta property="og:image:width" content="1200"><meta property="og:image:height" content="630"><link rel="shortcut icon" href="https://ssl.gstatic.com/images/branding/product/1x/drive_2020q4_32dp.png"><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Google+Sans:300,400,500,700"><link rel="stylesheet" href="https://www.gstatic.com/_/apps-file...ct=zgms/rs=AO0039u8vQ69dAstcr-Su9NdYDL8RthfjA"><script>_docs_flag_initialData={"docs-ails":"docs_cold","docs-fwds":"docs_sdf","docs-crs":"docs_crs_nfd","docs-shdn":0,"docs-tfh":"","info_params":{},"docos-eddmh":false,"docs-eohmo":false,"uls":"","docs-enpf":true,"docs-ce":false,"docs-api-keys":{},"buildLabel":"texmex_2021.01-Thu_RC02","docs-show_debug_info":false,"ondlburl":"https://docs.google.com","drive_url":"https://drive.google.com","app_url":"https://drive.google.com/file/","docs-itrf":false,"docs-mid":2048,"docs-eicd":false,"docs-icdmt":[],"docs-erdiiv":false,"docs-sup":"/file","docs-seu":"","docs-crp":"/file/d/11RpsORWOMJR2C_OGEqxkmUE6cRtrQCQY/view","docs-crq":"usp\u003dsharing","docs-ecvca":true,"docs-uptc":["lsrp","ca","sh","noreplica","ouid","dl","hi","usp","urp","utm_source","utm_medium","utm_campaign","utm_term","utm_content","aaac","sle"],"docs-doddn":"","docs-uddn":"","docs-cwsd":"","docs-gsmd":"","docs-al":[0,0,0,1,0],"docs-eiec":false,"docs-ndt":"Untitled Texmex","docs-prn":"","docs-as":"","docs-etdimo":false,"docs-mdck":"","docs-etiff":false,"docs-mriim":1800000,"docs-eccbs":false,"docos-sosj":false,"docs-rlmp":false,"docs-mmpt":15000,"docs-erd":false,"docs-erfar":false,"docs-ensb":false,"docs-ddts":false,"docs-uootuns":false,"docs-amawso":false,"docs-ofmpp":false,"docs-anlpfdo":false,"docs-eslars":true,"docs-phe":"","docs-pid":"","docs-icap":false,"docs-efs":false,"docs-ricocpb":false,"docs-etauihm":false,"docs-eoms":false,"docs-erep":false,"docs-effnp":false,"docs-eairh":false,"docs-edp":false,"docs-edlo":false,"docs-eismtl":false,"docos-sdp2":true,"docs-ejtlr":false,"docs-seadm":false,"docs-eab":false,"docs-eiasrpu":false,"docs-efmsh":false,"docs-ebbouf":false,"docs-eimtdl":false,"docs-embmd":false,"docs-ecgd":false,"docs-mss":false,"docs-iosdl":false,"docs-hft":"","docs-edsi":false,"docs-ececs":false,"docs-net-edsle":false,"docos-edab":false,"docos-ssf":true,"docs-esmc":false,"docs-ercwf":false,"docs-eem":false,"docs-efsii":false,"docs-text-elnma":false,"docs-elcfd":false,"docs-edmitm":false,"docs-enjec":false,"ecid":true,"docs-eir":false,"server_time_ms":1611013442694,"gaia_session_id":"","app-bc":"#d1d1d1","enable_iframed_embed_api":true,"docs-fut":"https://drive.google.com#folders/{folderId}","docs-isb":false,"docs-enct":false,"docs-agdc":false,"docs-an

BUT here you can see the image of Arrow.jpg , while in lblResult.text you see a text instead:
://drive.google.com/file/d/11RpsORWOMJR2C_OGEqxkmUE6cRtrQCQY/view?usp=sharing
starting with https of course.

PLEASE
S'il vous plaît monsieur, aidez moi! :)
Je suis un ancien programmeur, utilisant VB6 et maintenant je veux passer à B4A et B4J J'ai des centaines de documents numérisés au format jpg et je souhaite accéder à mes documents à partir de mon téléphone portable.
 
Last edited:
Upvote 0

Antoine EGO

Member
But the text was longer then 70'000 characters !
lblResult.text is included in the attached file
 

Attachments

  • Result.txt
    68.4 KB · Views: 190
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Try change the url to this syntax.
Before:
drive.google.com/file/d/11RpsORWOMJR2C_OGEqxkmUE6cRtrQCQY/view?usp=sharing

After:
drive.google.com/uc?export=download&id=11RpsORWOMJR2C_OGEqxkmUE6cRtrQCQY

Add https:// at the beginning.
 
Upvote 0

Antoine EGO

Member
Well, all want I want to do is to save my personal documents (as *.jpg) somewhere on internet, and get them back on my App when needed.

Hundreds of documents are scanned and named 1.jpg, 2.jpg, 3.jpg .....
Aim is to download the picture to an ImageView in my App.
Is there a way other than GoogleDrive?

(Files should be kept private of course!)
 
Upvote 0
Just use :
B4X:
https://drive.google.com/uc?id=11RpsORWOMJR2C_OGEqxkmUE6cRtrQCQY
The following code works:
B4X:
Sub Button1_Click

    Dim MyLink As String

    MyLink="https://drive.google.com/uc?id=11RpsORWOMJR2C_OGEqxkmUE6cRtrQCQY"

    DownloadImage(MyLink, ImageView1)

End Sub


Sub DownloadImage(Link As String, iv As ImageView)

    Dim job As HttpJob

    job.Initialize("", Me) 

    job.Download(Link)

    ProgressDialogShow2("Downloading Image.Please Wait",False)

    Wait For (job) JobDone(job As HttpJob)

    If job.Success Then

        iv.Bitmap = job.GetBitmap

        Else

            Log(job.ErrorMessage)

    End If

    ProgressDialogHide

    job.Release

End Sub
 
Upvote 0
Top