Android Tutorial Now,Push is easy for B4A(with androidpn)

server side:Android Push Notification | Free Communications software downloads at SourceForge.net
client with b4a:
activity:
B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   
   Dim startbtn,stopbtn As Button 
End Sub

Sub Activity_Create(FirstTime As Boolean)
startbtn.Initialize("btn")
startbtn.Text="StartListen"
stopbtn.Initialize("btn")
stopbtn.Text="StopListen"
Activity.AddView(startbtn,20dip,10dip,120dip,50dip)
Activity.AddView(stopbtn,20dip,70dip,120dip,50dip)

End Sub
Sub btn_Click
   Dim btn As Button
   btn=Sender
   If  btn.Text="StartListen" Then
      StartService(ser)
   Else
      StopService(ser)
   End If
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
 
End Sub
service:
B4X:
'Service module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
Dim push As PushLib
Dim notify As Notification
End Sub
Sub Service_Create
push.StartService("push","1234567890","192.168.99.100","5222",push.sym_action_chat)
End Sub
Sub push_onnotify(appid As String,title As String,body As String,uriStr As String)
   notify.Initialize
   notify.Icon="icon"
   notify.SetInfo(title,body,Main)
   notify.Sound=True
   notify.Light=True
   notify.AutoCancel=True
   notify.notify(0)
End Sub
Sub Service_Start (StartingIntent As Intent)

End Sub

Sub Service_Destroy
push.StopService
End Sub
And we should add the inside service to the manifest editor:
B4X:
AddApplicationText(
      <service android:enabled="true"
         android:name="com.NotificationService"
         android:label="NotificationService">
         <intent-filter>
            <action android:name="org.androidpn.client.NotificationService" />
         </intent-filter>
      </service>)
Before them you must download my library pushlib
to use this,you must make the appkey in b4a code and server are the same.
that's all enjoy yourself;)
 

Attachments

  • pushlib&demo.zip
    365.9 KB · Views: 972

kenfaber

New Member
Licensed User
Longtime User
Server Side Question

Stupid Question: If I want to write an app that sends the GPS coordinates of my kid's phone to my phone. Why do I need a to obtain and configure my own web server to be the middle man? I would think that I could just send my push messages to Google cloud services it would route them to all apps who are have been registered as listening to my AppId, right?

I guess, I misunderstand what role Google Cloud Services plays.

Thanks for the code. It'll really help me, but I am bummed out that I need to obtain a web server to make this work. I guess I am confusing the term "Cloud Services" with "Cloud Server". Google Cloud Services is really just an API not a location in the cloud where work is done on your behalf according to your bidding, right?
 
Last edited:

quaker

Member
Licensed User
Longtime User
hi good evening

I have tried your library.It seems(to me) this doesnt work.I put in situation:

Tablet ip:192.168.1.99
Pc ip:192.168.1.125

PC sees tablet with "ping" and tablet sees pc with ping.i Subscribe the server using your example and the pc ip as host.

I previosly loaded the server in the pc.It works as the admin panel using 127.0.0.1 is there.But when i go to the connected users tab,there is nobody.Also in the log does not put anything about user connected or similar.

Thanks for your help!.
 

wl

Well-Known Member
Licensed User
Longtime User
Hello,

Does anyone have a C# (.NET) server implementation example ?

Thanks !
 

Reinosoft

Member
Licensed User
Longtime User
Question

Hello,

I downloaded and tested your lib; it looks great; :sign0142: I want to add my frontdoor-bell to my phone, the signal is already received in VB6; which command do i have to post to the phone?

I created a Winsock connection in VB6, it receive a XML command from your lib, but when i senddata back, the App on the phone doesn't react.

The app disconnect after app. 30 sec, do I have to create a interval using a timer, and reconnect for data?
 

cellicom

Member
Licensed User
Longtime User
Great Lib!
But one question about it...

There is way "to do something" when i 'click' the notification?
there is a "on click" event?

Thanks.
 
Top