Android Tutorial Accessing third party Jar with #Additionaljar and JavaObject - Picasso

ppgirl

Member
Licensed User
Longtime User
In activity module.

this is B4A's java code

//BA.debugLineNum = 120;BA.debugLine="wdj.InitializeNewInstance(\"com.qq.e.ads.InterstitialAd\",Array (GetContext ,\"1101721111\",\"9079537215654558411\"))";
mostCurrent._wdj.InitializeNewInstance("com.qq.e.ads.InterstitialAd",new Object[]{(Object)(_getcontext().getObject()),(Object)("1101721111"),(Object)("9079537215654558411")});
 

stevel05

Expert
Licensed User
Longtime User
Can you zip and post your project (and the library jar) and a link to the documentation / demo code.
 

ppgirl

Member
Licensed User
Longtime User
Hi Stevel,

There is the SDK and B4A demo code.

SDK is a whole Java demo code sample.zip and jar.

B4A demo code sdkdemo.zip is made by me , you can check the problem.

please copy those jar to library directory.

Thanks!
 

Attachments

  • sdkdemo.zip
    384.6 KB · Views: 663
  • android-query-full.0.26.7.jar
    204.4 KB · Views: 588
  • android-support-v4.jar
    472.9 KB · Views: 564
  • gdt_mob_release_v4.2.447.jar
    146.1 KB · Views: 514
  • sample.zip
    62.5 KB · Views: 643

stevel05

Expert
Licensed User
Longtime User
OK, the constructor doesn't want the context as an argument, it wants the activity, which you can get using this code (Requires the reflection library):

B4X:
Sub GetActivity As Object
    Dim R  As Reflector
    Return R.GetActivity
End Sub

Then:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")

    wdj.InitializeNewInstance("com.qq.e.ads.InterstitialAd",Array (GetActivity ,"1101721115","9079537215654558411"))
    wdjop1=wdj.CreateEvent("com.qq.e.ads.InterstitialAdListener", "callbackwdj", Null)     
    wdj.RunMethod("setAdListener",Array(wdjop1))
    wdj.RunMethod("loadAd", Null)   
End Sub

Without the JavaDoc, it's not going to be possible to help much further I'm afraid. I tried translating their website into English, but couldn't find anything useful.

I hope this get's you up and running.
 

ppgirl

Member
Licensed User
Longtime User
Great! It is OK , the SDK is a AD SDK.

I forget it can get activity by Reflector.

Thanks!!!
 

ivan.tellez

Active Member
Licensed User
Longtime User
Hi

Im triing to use use an external jar to render SVG files https://code.google.com/p/androidsvg/

B4X:
Sub GetSVG(SVGString As String) As JavaObject
  Dim jo As JavaObject
  Return jo.InitializeStatic("com.caverock.androidsvg.SVG").RunMethod("getFromString", Array(SVGString))
End Sub




Sub Button1_Click
   Dim Canvas1 As Canvas
   Dim MyBMP As Bitmap
   MyBMP.InitializeMutable(512,512)
   Canvas1.Initialize2(MyBMP)
   
   Dim SVGString As String = File.ReadString(File.DirAssets, "android.svg")
   
   'Log(GetSVG(SVGString).RunMethod("getDocumentWidth", Null))     'This works
   
   'GetSVG(SVGString).RunMethod("renderToCanvas", Array(Canvas1))   'This is not working
   'GetSVG(SVGString).RunMethod("renderToPicture", Null)        'Returns an Android.Graphics.Picture, How to convert to Android.Graphics.Bitmap?
End Sub

I can load the SVG file, but cant use the render methods, any idea in how to get this working?

Thanks
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
The B4a Canvas is a wrapper for the android.graphics.Canvas object. You need to get the android object from the wrapper:

B4X:
Dim CnvJO As JavaObject = Canvas1
GetSVG(SVGString).RunMethod("renderToCanvas", Array(CnvJO.GetField("canvas")))

I hadn't come across the android.graphics.Picture class, but looking at the documentation, to make it usable in B4a you'll need to render it to a canvas. So it seems a bit redundant unless you want the functionality of the Picture class itself. A quick test didn't work properly so that'll be an investigation you'll need to carry out if you want to use it.
 
Last edited:

ivan.tellez

Active Member
Licensed User
Longtime User
Hi, can you help me with another question please, how can you use a Type that its not accesible in B4A

For example, if there is a function in the java code like

public RectF getDocumentViewBox()

How can use the RectF object in B4A? If I use a standard Rect, it raises an error

B4X:
Dim tRect as Rect

Thanks
 

ivan.tellez

Active Member
Licensed User
Longtime User
Wow, it works the other way too.

B4X:
    Dim rect1 As JavaObject
    rect1.InitializeNewInstance("android.graphics.RectF", Null)
    rect1 = SVG.RunMethod("getDocumentViewBox", Null)


Thanks
 
Last edited:

Steini1980

Active Member
Licensed User
Longtime User
B4X:
GetPicasso.RunMethodJO("load", Array(url)).RunMethodJO("into", Array(img1))

Works fine, but how can I save the Image in ImageView "img1" ???
Img1.Bitmap seems empty, but the Image will be shown on Imageview.

Could someone help me saving the Image loaded via Picasso into File?!
 

Steini1980

Active Member
Licensed User
Longtime User
At the moment I have tried only without callback event. But I have used Sleep Function to wait 10 Seconds, i saw the picture in ImageView befor timer was zero. But the img1.Bitmap was empty too. Did you think I should try with Callback? Maybe the Bitmap will stored as Background Image or if possible only drawed at the control? What can I try else? Is it possible to catch the data directly from content:// url, without storing in ImageView (I also tried via httpUtils2 but it doesn't it seems only working with http:// urls?
 

Steini1980

Active Member
Licensed User
Longtime User
If I try Callback with Log("IMG1 BG: "& img1.Background &" BMP: " & img1.Bitmap,True) then

Background has a Value and Bitmap is Null in Callback.
Because Background has also a Value when I start Activity, I don't know if the value has changed after Callback.

How can I catch the Background Value as File?
 
Last edited:

a2stepper

Member
Licensed User
Longtime User
i have copy and pasted your example from above and get this error:

Parsing code. Error
Error parsing program.
Error description: Attribute not supported: additionaljar
Occurred on line: 16
#AdditionalJar: picasso-2.2.3

using B4A version 3.20.
is there anything else i need to do to get working.
thanks.
paul
 

a2stepper

Member
Licensed User
Longtime User
when i copy and pasted the code from the above, and ran it i got this message

#AdditionalJar: picasso-2.2.3 is unknown??

im using B4A ver 3.20

is there something else to get working?
thanks.
paul
 

tunderin

Member
Licensed User
Longtime User
A no java knowledge question - can I use #AdditionalJar with a .so library?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…