Airpush Library

ssg

Well-Known Member
Licensed User
Longtime User
Important: The below is for the older Airpush version. Version 5 requires a customised SDK for each developer, and the below library does not work with Version 5.


============== version 4 steps start ==================

Hi All,

Attached is the Airpush library. It seems to work fine for me so far after a few days of testing.

Those that have used the beta version from my other posts, please update to the library attached here.

How to use:

- Register at Airpush. Create a new app and get the AppId.

- Download the Airpush sdk.

That should be it for Airpush side. Please note, they might take up to 24h to push your first ad.

- Add the attached libraries and Airpush SDK to your extra libraries folder, and refresh or restart B4A.

- Select both Airpush and MESAPLib.

Code in B4A:

B4X:
Sub Process_Globals
   Dim ap As APAdView
End Sub

Sub Activity_Create(FirstTime As Boolean)
         ap.Initialize("ap", <appid>, False)
 'your appid, the event "ap" will not fire though, False for live ads

End Sub

In your manifest file:

B4X:
<!-- Airpush Code Start-->
<activity android:name="com.airpush.android.PushAds"
android:configChanges="orientation|keyboardHidden"/>
<receiver android:name="com.airpush.android.UserDetailsReceiver"/>
<receiver android:name="com.airpush.android.MessageReceiver" />
<receiver android:name="com.airpush.android.DeliveryReceiver" />

<!-- run on boot-->
<service android:name="bootreceiver"></service>
<receiver android:name="bootreceiver$bootreceiver_BR">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<!--run on boot end-->

<service android:name="com.airpush.android.PushService">
<intent-filter>
<action android:name="com.airpush.android.PushServiceStart<Your appId>"/>
</intent-filter>
</service>
<!-- Airpush Code End-->

* Please replace <Your appId> with your appid

To get the ads to run on start up, a service needs to be called on boot.

- In your B4A, add a new service module called BootReceiver, mark it as "start at boot".
- add following code:

B4X:
Sub Process_Globals
   Dim glapad As APAdView
End Sub

Sub Service_Create

End Sub

Sub Service_Start (StartingIntent As Intent)
   
   glapad.Initialize("glapad", <APPID>, False)

End Sub

In manifest, permissions:

B4X:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.VIBRATE"/>(Optional But
Highly recommended to enhance your revenue stream)

- mark project > do not overwrite manifest file.

Compile and have fun!

There is no code to add this to the application as it is not needed, it launches some background process that will periodically get the ads depending on how airpush is set up.

Please feedback on you success :D

Good luck all!

********Update 23rd October 2011***********
Airpush has added a new ad format called Icon Ad.

The attached library is updated for this. Please note that some coding changes are required:

1 - The library type is now called MESAPLib (used to be APADView)
2 - The initialise method signature is changed, the IDE ToolTip should help you figure out what to put in.

Some new permission are required in the manifest file (the 2nd and 3rd one MIGHT be optional):

B4X:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>
<uses-permission android:name="com.android.browser.permission.WRITE_HISTORY_BOOKMARKS"/>

Give it a spin folks... the CPM based on my live apps is at $12... excellent!!

Attached is the new library. Please download the Airpush SDK from their site, and mark your apps for Icon Ads from the Airpush dashboard.
 

Attachments

  • Airpush.zip
    2.3 KB · Views: 774
Last edited:

XverhelstX

Well-Known Member
Licensed User
Longtime User
Great work ssg!
I haven't tested it yet, but I wonder if I can see the java source code.
You wrapped the library right? (As I actually don't know on how to do it.)

Do you have some small tut or example or something?

Thanks and good job!

Tomas
 

ssg

Well-Known Member
Licensed User
Longtime User
Hi Tomas,

Thank you for the kind words.

I'm only just trying out the java parts. Initially I released the library with AbsObjectWrapper extention, which I guess was the wrong way of going for this library.

The following is code for the initialization, which pretty much handles everything else (the provided library handles most stuff). This code just creates an instance of the Airpush object thingy:

B4X:
public void Initialize(final BA ba, String EventName, String PublisherId, Boolean testMode) {
   new Airpush(ba.context.getApplicationContext(), PublisherId, "airpush", testMode);
}

Import using the airpush library: import com.airpush.android.*;

The rest of the setup was following your excellent tutorial :sign0188:
 

ssg

Well-Known Member
Licensed User
Longtime User
For what it's worth, here is how I did it back then with the AbsObjectWrapper:


B4X:
public class MESAirPush  extends AbsObjectWrapper<Airpush>{

public void Initialize(final BA ba, String EventName, String PublisherId) {
 setObject(new Airpush(ba.context.getApplicationContext(), PublisherId, "airpush", false));
         
}   

}

The setObject method is used to create an instance of the object you have wrapped.

getObject().xxx gives you the properties and methods of the object.

Do ask if you need any more details, I'll try to give you any samples I've come across...

Cheers!
 

susu

Well-Known Member
Licensed User
Longtime User
That's so great, SSG! Hope you'll create more ad libraries.
Thank you :D
 

magarcan

Active Member
Licensed User
Longtime User
Thanks for the lib. I've updated my apps, and it's time to use it.

I've some question. After reading the main post I think there are two ways to use the library:
- Run ads only while user is using our app (first code).
- Run ads at startup, so we have to create a service (second code).
Depending of the way, we have to use two different codes with two different requisites in the .XML, am I right??

Thanks!!
 

ssg

Well-Known Member
Licensed User
Longtime User
Hi,

you are quite right in what you mentioned. please note that this library keeps on running in background once it is started, so ads are shown even when your app is not running, if the user has run your app at least once.

if the user uninstalls your app though, then the background process would end too.

cheers!
 

magarcan

Active Member
Licensed User
Longtime User
Hi,

you are quite right in what you mentioned. please note that this library keeps on running in background once it is started, so ads are shown even when your app is not running, if the user has run your app at least once.

if the user uninstalls your app though, then the background process would end too.

cheers!
So, which is the difference between the two codes?? If you use a service, ad will be shown every day even if user doesn't execute the app, and if you load ads from the app, ad will be shown only if user load app, doesn't it?? :eek:
 

ssg

Well-Known Member
Licensed User
Longtime User
** service code -> starts the background process everytime user boots up

** load ads from app run -> starts the background process immediately, and as long as the user has the phone turned on, it will keep getting ads in the background to be displayed.

the ads are running independent of your app. it is like start once and forget about it, it keeps requesting ads in background depending on how you've set up your airpush account.

hmm... hope i'm making it clear, lol, I am running out of ideas in how to explain it :p
 

magarcan

Active Member
Licensed User
Longtime User
** service code -> starts the background process everytime user boots up

** load ads from app run -> starts the background process immediately, and as long as the user has the phone turned on, it will keep getting ads in the background to be displayed.

the ads are running independent of your app. it is like start once and forget about it, it keeps requesting ads in background depending on how you've set up your airpush account.

hmm... hope i'm making it clear, lol, I am running out of ideas in how to explain it :p
I'm not able to see very big differences. Which one is the best method?? I think using service...
 

ssg

Well-Known Member
Licensed User
Longtime User
no differences really..

yes service would be better way to go as it means you only need to maintain code in one place, plus you could use it at boot and it can be called when your app starts.
 

Gigatron

Member
Licensed User
Longtime User
To learn how Admob working take 7 day for me.

Now to learn how Airpush working will take 7*10 day for me :BangHead:

SSG can you please reduce instructions , or explain basicaly !


ENGLISH is made for not understand Computer language !!!

Y'a t-il quelqu'un qui peux m'expliquer ça en Français ????


A ++
 

ssg

Well-Known Member
Licensed User
Longtime User
yeah, i know the steps are rather tedious... hope you will be able to follow...

it is tough for first time only... after that it's almost a copy paste thing...

good luck!

PS - anyone else wanna try writing a short tutorial on the steps?

Cheers!
 

magarcan

Active Member
Licensed User
Longtime User
Maybe I'm wrong but this is what I do:
-Register at Airpush.
-Create a new app and get the AppId.
-Download SDK
-Copy, MESAPLib.jar, MESAPLib.xml, AirpushSDK.xml and AirpushSDK.jar (from SDK) to library folder.
-Add a new service module called BootReceiver, mark it as "start at boot".
-Add the following code in the service, changing my APPID (1234):
B4X:
Sub Process_Globals
   Dim glapad As APAdView
End Sub

Sub Service_Create

End Sub

Sub Service_Start (StartingIntent As Intent)
   
   glapad.Initialize("glapad", 1234, False)

End Sub
-Mark not to overwrite manifest .XML
-Add this to my manifest .XML file inside permissions:
B4X:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.VIBRATE"/>

It's all right?? I've not received any ad yet...

Thanks!!!
 

ssg

Well-Known Member
Licensed User
Longtime User
on thie first page, you need to add the section that starts with this piece in the manifest file..

<!-- Airpush Code Start-->

the rest of your steps look fine.

for ads to show, sometimes the ad will only be shown 24hours later, sometimes you dont get ads at all coz there are no ads targetting your location.

what you could so, add the missing part to your manifest, run your app, then in about 5 minutes, refresh your dashboard in airpush website. see if the new user count has increased by 1.

that would mean that your phone is now "registered" with airpush, just that they havent sent out an ad yet..

hope things work out fine for you!
 

magarcan

Active Member
Licensed User
Longtime User
So, independently of the method I use for loading ads (from my app or from a service), this code is needed, doesn't it?
B4X:
<!-- Airpush Code Start-->
<activity android:name="com.airpush.android.PushAds"
android:configChanges="orientation|keyboardHidden"/>
<receiver android:name="com.airpush.android.UserDetailsReceiver"/>
<receiver android:name="com.airpush.android.MessageReceiver" />
<receiver android:name="com.airpush.android.DeliveryReceiver" />

<!-- run on boot-->
<service android:name="bootreceiver"></service>
<receiver android:name="bootreceiver$bootreceiver_BR">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<!--run on boot end-->

<service android:name="com.airpush.android.PushService">
<intent-filter>
<action android:name="com.airpush.android.PushServiceStart<Your appId>"/>
</intent-filter>
</service>
<!-- Airpush Code End-->

Now, I'm at work but as soon as I arrive home I'll try it.

Thanks again!!
 

magarcan

Active Member
Licensed User
Longtime User
I've updated de code, but it's still not working for me :BangHead:
B4X:
<action android:name="com.airpush.android.PushServiceStart<Your appId>"/>
If my AppId were 1111, this should be:
B4X:
<action android:name="com.airpush.android.PushServiceStart1111"/>
Doesn't it???

An other question. Where have I to write the code in the manifest file??
I've copied all code just before this:
B4X:
...
</application>
   <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.VIBRATE"/>

</manifest>
Is it ok??
 

ssg

Well-Known Member
Licensed User
Longtime User
hi,

you manifest seems fine.

just out of curiosity, since you've moved the airpush code to a service module, where are you calling your startservice from?
 
Top