Android Tutorial Simple Push Framework

It is recommended to use Firebase for new projects: FirebaseNotifications - Push messages / Firebase Cloud Messaging (FCM)

This solution allows you to use the standard GCM push framework without an online server.

SS-2013-12-12_15.48.10.png


You should first be familiar with GCM and get an API Key and Project id as explained here:
Android push notification (GCM) framework and tutorial

The desktop solution is based on this B4J project: Building a mini "Email based server"

When a user registers the device, an email is sent to the desktop tool. The desktop tool then adds the device to an internal store. If the desktop tool is not online then nothing bad happens. The mail will wait until it the tool is started.

The emails are only used for the registration process.

Note that you can send to multiple targets at once with this solution (unlike the other solution).
As it is written in B4J it should be simple to extend it as needed.

In order to use it you should set the ApiKey variable in the B4J project as well as the mailbox parameters.

You also need to set the mailbox parameters on the device (PushService) and set the SenderId in the Main module.

Tips / Notes

- The B4J project depends on jMsgboxes library (and other internal libraries). It also requires B4J v1.05+.
- If you plan to distribute your app on many devices then you should probably not use a free mail service such as Gmail for the devices. You can use the default email client instead. However in that case it is better to "obfuscate" the message before sending it as the user will see the mail content.
 

Attachments

  • PushDevice.zip
    8.6 KB · Views: 2,812
  • PushDesktop.zip
    6.3 KB · Views: 2,517
Last edited:

le_toubib

Active Member
Licensed User
Hi all
I got the desktop app working ( only after disabling avast Antivirus), and reading old email msgs from the specified account.
But whenever I click register on my phone I get the toast msg : error sending request.
Any clue???
 

le_toubib

Active Member
Licensed User
Have you checked the logs for the full error message?

Have you configured the email account variables (user, password,...) ?
thx for replying
yes and yes.

I used the same email user and pass on the b4j desktop app and it worked fine

edit : found it , I had to enter the full email in the user i.e : "user @ gmail.com" instead of user name only, unlike in B4J app

edit ; now - after successfully registering a device - desktop app didn't start until I upgraded to JFX 2.01 library, but still when I attempt to send a msg , it says : please select a device. (off course I m selecting a device)
edit : just restarting fixed it , now it s working great thanks :)
 
Last edited:

bravox

Member
Licensed User
Hello,
Email based GCM push application works perfectly. But I just wonder, why I can not receive an email if it is already received before?
It is a standart gmail account, I can see the mails and they are still exist, still unread. there are several emails are in the "inbox" but if I received once the server says "no new mails".
what I have to do?

thanks in advance
Bravox
 

Devendra

Member
Licensed User
i am getting the following error in the android device, "INVALID_SENDER" Please correct me what i have done wrong, My Desktop app With B4J works fine,
only the registration process of the android app side does not work
 

Devendra

Member
Licensed User
Have you updated the value of SenderId in the Android app?

Yes I Have done in the Public variable, I debug the app as well, But i am getting this error, I have not changed anything in the coding as well.

I have included the ( net ) library as well. and jmsgbox library as well.
 

gudino jose luis

Active Member
Licensed User
hi erel
I'm using the Simple Push Framework, it works perfect.
Now, I have a little problem, I have developed an application to request taxi service, and I sent demos app a few countries,
APP is installed in a few telephone and in a few countries, therefore this using my mail from gmail to be set up to push in different places at once, gmail me send an email with the following notice: "It has been initially suspicious avoided Login ".. the question is how to configure mail security to not send this message

regards
 

Ricardo Bunschoten

Active Member
Licensed User
Second Question if you register a device name and you register it on a second device with the same name it overwrites the data of the first test.

is it possible in the code to create a device name on base of the device id ? so it creates a unique device name ?
 

Ricardo Bunschoten

Active Member
Licensed User
I want to share my findings.

I figured out how to use the phoneid as username so you will not have any duplicate names.

The app now auto regs and closed after the push service is done.

You will see the message Action completed successfully (this can take some seconds)

This because otherwise the username and data will be overwritten in the database of the java console.

B4X:
#Region Module Attributes
    #FullScreen: False
    #IncludeTitle: True
    #ApplicationLabel: Filmspeler notifier
    #VersionCode: 1
    #VersionName:
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

'Activity module
Sub Process_Globals
    'Set this field to match the project ID in Google Console.
    Public SenderId As String = "xxx"
    Public DeviceName As String
End Sub

Sub Globals
    Dim pid As PhoneId
End Sub

Sub Activity_Create(FirstTime As Boolean)
        DeviceName = pid.GetDeviceId 'Get Imei and use it as unique name
        Log(pid.GetDeviceId) 'log imei
     
    CallSubDelayed2(PushService, "RegisterDevice", False)
    Activity.finish
 
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Unregister(Name As String) 'ignore
    DeviceName = pid.GetDeviceId
    CallSubDelayed2(PushService, "RegisterDevice", True)
End Sub

Only thing i know look for is in the java console a option to select or deselect all usernames (entrys)
 

Ricardo Bunschoten

Active Member
Licensed User
is it possible in the java console/mail client to set all device standard on choosed ?
Or a little box that you can choose sellect all ? If you have like 50 devices you have to click a lot every time.

Is that possible Erel ?

Thank you.
 

Ricardo Bunschoten

Active Member
Licensed User
I changed the code in the desktop client so it's now all entrys are auto checked

B4X:
Private Sub ShowDevices
    tvDevices.Root.Children.Clear
    For Each key As String In devices.ListKeys
        Dim ci As CheckboxTreeItem
        ci.Initialize("", key)
        tvDevices.Root.Children.Add(ci)
        ci.checked = True
 

Ricardo Bunschoten

Active Member
Licensed User
I have a little question about this service. It's working awesome but..

I want to send messages to registered devices when a update is available i want to send them a message.

But this message appears and then goes away and is only visible as a icon.

I want a message box that they have to click away so they are notified that a update is available.

is this possible with this service ?

Thnx in advance
 
Top