B4A Library Parse Library – Push Notifications and Cloud Storage

Parse service is shutting down: http://blog.parse.com/announcements/moving-on/

Overview


This library is a rather extensive overhaul of and update to Erels’ original Parse library.

Parse is a company that provides several services for mobile applications and has just been purchased by Facebook so it looks like it should continue to be a stable and reliable service.

You create an account on Parse.com and then create what they call “Applications” which would usually correspond with individual Android applications but don’t have to, so several different Android applications could access a common body of data in a single Parse application. Within Parse applications there are “Classes” of data which look much like a database table and contain ParseObjects which look like an individual row of data in a table.

Capabilities

The two major uses for this library are as follows

1) Providing cloud based data storage and retrieval for data held in the individual Parse Applications in a simple way including querying the stored data. No need to mess with HTTP and networking, it is all done for you in an object oriented fashion.

2) Supporting Push Notifications which can be instigated both from the Parse Web Dashboard of your Parse account and, if you have enabled it in the Dashboard for that Parse application, also from devices running the corresponding Android application. Push Notifications are sent in the context of the individual Parse Applications whose Android applications have registered to receive them but individual devices, or groups of devices, may be selectively targeted by using “Channels”.

Parse offer three levels of service, the first being free as long as you keep within their limits which are one million API Requests per month, one million Push Notifications per month and one Gigabyte of storage use. You can exceed these limits without upgrading to the next paid plan, which is presently 199 US dollars per month if you register a credit card. You can exceed these limits and be charged 7 US cents per one thousand excess API Requests, 20 UC cents per one thousand Pushes and 20 US cents per one Gigabyte of excess storage. There is information on your usage of all three available in your Parse Dashboard.

An API Request is a single network operation which are the ones that raise Basic4android events from the library.

The definition of the number of Pushes is “The total number of push notifications queued for delivery to a client device”. I may be being stupid but that seems ambiguous to me and I don’t understand whether that means that the total number of Push Notifications counts as each single message sent to lots of devices or as the total number of devices to which a single message is sent. I suspect the latter. If anyone knows definitively than please post and I will amend this paragraph.

The amount of storage used is obvious and needs no explanation.

Please read the Parse Android Guide, in the Parse.com Documentation section of their web site, for more information about how to use this library. The Parse Android API document might also be useful occasionally. The mapping of this library objects methods to those of the Java API are usually obvious.

All the operations which need to access the Parse online service are done asynchronously and raise events when complete whose parameters include a Success indication. If an error occurs Success will be False and a ParseException with a message describing the error will be placed in LastException. If necessary this should be processed in the event code as there is a possibility that a further error could occur in another asynchronous call that would overwrite the existing LastException.

Note that these asynchronous operations do not necessarily complete in the order in which they are invoked. To deal with this possibility a TaskID parameter is provided in each call that can be used, if required, to identify which of several possible method calls has just completed.

Installation instructions

In order to use this library you should sign up to Parse.com, go to your Dashboard and create a new Parse application called whatever you feel like calling it. You will need two keys, Application Id and Client Key, which you will find under the Settings for your application. Both are required and need to be copied to the appropriate Process Global variables in the demo.

You also need to download the Parse Android SDK from the Downloads section of the Parse.com web site. Inside the zip file you will find a file named Parse-1.2.4.jar or similar. Copy this to your Additional Libraries folder and rename it ParseNative.jar. Also put Parse.jar and Parse.xml from the demo archive in your Additional Libraries folder.

As detailed in the help for Parse. EnableNotifications in order for your application to receive Push Notifications you need to add the following to the Manifest Editor in your project.
B4X:
SetApplicationAttribute(android:name,"anywheresoftware.b4a.objects.ParseObjectWrapper$ParseApplication")

AddApplicationText(<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
  <intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED" />
    <action android:name="android.intent.action.USER_PRESENT" />
  </intent-filter>
</receiver>)

Version 1.1 of this library specified the Parse keys in a Parse.Initialize method. This method no longer exists in version 1.2 and later. This is because it it was called from within an Activity, but if Android killed your process and then tried to restart the Parse Service this failed because the service started without the activity being created and so was not initialised correctly. Initialisation now occurs on Application creation and requires the library Application class name to be registered in the manifest and the Parse keys to be specified as an xml resource. When the application is loaded you will see the values in the xml file echoed to the filtered logs.

You also need to place a file called res.xml in your project Objects/res/xml folder and make it read-only. The xml folder does not exist in the project archive but will be created at your first compile. The contents of res.xml should specify your Parse keys as follows
B4X:
<!--?xml version="1.0" encoding="utf-8"?-->
<data>
   <data1 value="YourParseApplicationAppID" />
   <data2 value="YourParseApplicationClientKey" />
</data>

The demo project is already set up to receive push notifications. Try sending one from your Parse Application using the Parse Dashboard.

Run the demo and have a play.

Issues

I have found that using IE10 to send a Push from the Parse Dashboard usually causes the Push to be sent twice, you will see this in the Dashboard list of pushes sent and also at the device and of course they both count towards your free total. Chrome appears to work correctly and sends only one. The work-around is obvious.

The Parse library starts a service called PushService to receive the Pushes and which you can see in Settings -> Apps -> Running -> ParseDemo. Prior to Parse SDK 1.2.4 sometimes this service stopped receiving Pushes and the Process needed to be stopped using a Task Manager and restarted. Parse SDK 1.2.5 should have fixed this.

EDIT:- Version 1.2 now posted. See post #6 for details.

EDIT:- Version 1.3 now posted. See post #13 for details.

EDIT:- Version 1.4 now posted. See post #17 for details.
 

Attachments

  • Parse1.4.zip
    43.2 KB · Views: 1,294
Last edited by a moderator:

derez

Expert
Licensed User
Longtime User
Edit: Sorry Sorry Sorry - found the problem, I forgot to enable push notifications in Parse.com
Now read the rest...because it works and it is not in the example.


Hi
There is a ParsePush object in the library which should send push notifications from the application.
I wrote the following definitions:
B4X:
 If FirstTime Then
      Parse.SetLoggingLevel(2) ' Verbose logging for testing only - remove for a real application
      Parse.TrackOpening   
      Parse.EnableNotifications(Notification)
      Parse.Subscribe("Channel1", Notification)
      GPS.Initialize("GPS")
      pofix.Initialize("Location")
      
      push.Initialize
      push.SetChannel("Channel1")
      push.SetMessage(name & " Updated Location")
  End If
and later there is
B4X:
push.Send("push",2)

This is in according to what the tutorial instruct:
ParsePush push = new ParsePush();
push.setChannel("Giants");
push.setMessage("The Giants just scored! It's now 2-2 against the Mets.");
push.sendInBackground();

The push is reported as success in Sub push_DoneSend but the PN is not recieved by the application.
In the Parse.com I have the attached report on push notifications, while the problem is that it was sent to 0 subscribers.
I thought maybe it sends to all but the initializing app, so I checked with two devices, but no.
What is wrong ?
 

Attachments

  • 1.png
    1.png
    34.1 KB · Views: 240
  • 2.png
    2.png
    12.8 KB · Views: 229
Last edited:

urikupfer

Member
Licensed User
Longtime User
Hi Agraham
Is there a way to add the ProgressCallback function for getting the progress
of uploads and downloads of big files.
They have this option in the android api.
Uri Kupfer
 

Widowmaker

New Member
Licensed User
Longtime User
Nobody answered me...:sign0148:
I originally asked:

I will be notified by the push that a sale(s) has occurred on my online shops and the amount , using channels I would want to have one alert per shop but keep track of the total sales, eg after 2 hours shop xxxx has had 14 sales for £325.66 sort of thing, and not a long list of 14 notifications just 1 per shop. I would need access to notifications to update the title and text, I would also like a different sound for each shop if poss.

Having looked into it there does not seem to be a way to control the push notification so I thought I would just control the message , but am I likely to get 1 PN for every alert or will the system combine them the way the ordinary notifications work, so if the phone has not been looked at for a while will it say blahblah app with 6 as the number of total PN's or will it trigger 6 separate PN's in the notifications area, if the first scenario is the case when my activity is resumed by the user when they touch the notification how do I combine all the data from all 6 PN's

thanks in advance if i'm asking silly stuff, I can program honest but sometimes I need a push to go in the right direction.:BangHead:
 

derez

Expert
Licensed User
Longtime User
Widowmaker
I'm learning this myself so this answer is by no means an expert answer...
Every notificatation sent by an application (=shop) will be recieved separately, I don't see a way to combine them. You can put the name of the shop in the push.setmessage and so you'll have the name of the sending shop in the text of the notification.
 

Widowmaker

New Member
Licensed User
Longtime User
thanks for replying, i found that out as well, shame really, it would be nice if i could interact before the user selects it, but as you say this is not possible, if i do it another way and get the info from the parse db when they select the pn it will just be pointless cos they could still have loads of pn's to click, if i could cancel the pn's i could at least create my own, but that is not possible either afaik.

if i could get into the parse library code i could make it do what i want, is that possible or is the source scrambled.
 

hookshy

Well-Known Member
Licensed User
Longtime User
Could you add an example on how to send PN from device using parsepush object ?
I don't understand how to use taskId , please explain.
Thanks
 

mading1309

Member
Licensed User
Longtime User
First of all thanks that to write this useful lib and make it public.
I want change or extend the GCM service of google with the Parse Push service.
GCM referenced to a service not activity. Is the notification in the status bar the reason for the activity?

From the demonstration application is I exchange the activity Notification and want use my one one.
For the first step I just renamed the activity to >>MyOne<<.
After renaming I receive an error message

"Module Notification not found"

Seems the activity name notification is "hard coded".
The subscribe method and the methods for enable and disable notification comes with an parameter.
I guess this parameter might reference to the class shall be called in case a push message arrived.

Now there are questions:

1) The notification in the status bar is a must with this library? I need to receive the Information send by the push service in the background and in a silent way. My application checks the received data and decide what to do.
2) The parameter of the method subscribe reference and for disable and enable the notification the same. Is it a must for this wrapper library and what use are these parameters?
3) Does the Parse.com push service make use of any Google services comes with the Playstore similar Google push service?
4) To subscribe the push service, is it a must to reference to an activity? Can it be a service also? At least the required type is class. I cannot give a try because receiving a push message the activity Notification is called and not myone. What I've done wrong?

thanks for some answers and help

Mading
 

boten

Active Member
Licensed User
Longtime User
Why is data1 & data 2 (from RES.XML) displayed on the log, whatever SetLoggingLevel I use, or not use at all?
Anybody who is using my app and looking a the log will be able to manipulate the app on Parse.
 

holdemadvantage

Active Member
Licensed User
Longtime User
Why is data1 & data 2 (from RES.XML) displayed on the log, whatever SetLoggingLevel I use, or not use at all?
Anybody who is using my app and looking a the log will be able to manipulate the app on Parse.

sorry i don't understand, what do you mean with "anybody will be able to manipulate my app on parse"? To send a push you have to log into your account? let me know ty
 

boten

Active Member
Licensed User
Longtime User
I'm not talking about push.
If a user runs my B4A-app on a rooted device they can see the log, hence my keys to parse, hence they can write an app to manipulate my data.
 

msawada

Member
Licensed User
Longtime User
Hi agraham, as usual I love your libraries. Great work! I do have a question regarding whether or not you have plans to add the saveEventually() method or if it is somehow already in this library.
Thanks Mike
 

mickeyk600

Member
Licensed User
Longtime User
Hello Agraham ,
I have been testing your parse Library the last few days and it is fantastic and easy to use – Thanks

One important methods is missing: Sending Push notification via Json. If you Look at the parse Site under send Push notification,
You will see that they allow sending Push notification via json , this allows creating a custom intent that will be fired at the receiving side of the push notification and we ( the app developers) will be able to intercept it and provide our app a custom behavior, when the notification arrives.
I envision 2 methods : SetMessage(text) SetMessage2(json) the 2nd one that takes Json and allow sending anything (if we omit the “alert” and “title” the notification will not show on the notification tray, sometime it is needed)
From Parse documentation:
From parse:
*****************************************************************************
action: (Android only) the Intent should be fired when the push is received. If not title or alert values are specified, the Intent will be fired but no notification will appear to the user.
**************************************************************************************

What do you think?
Thanks in advance
Mickey
 

boten

Active Member
Licensed User
Longtime User
Is there a way to get the Analytics information on Parse using the Parse Lib?
I'm interested in "retrieving" the number of API requests, Push notifications and App Opens by dates.
This info can be seen in Dashboard/Analytics but how can I get this info into my app (possibly by some query)?
 

boten

Active Member
Licensed User
Longtime User
ParseQuery.Limit=-1 does not work, retrieves only 100.

ParseQuery.Limit=1000000 will retrieve more than 100 (of course up to 1 million)

Edit:
Max retrieved results is 1000 (Parse documentation).
A query.Skip (query method) is "missing" from the parse lib

Skip is described in the Parse documentaion as:
Skips a number of results before returning. This is useful for pagination of large queries

If my class contains over 1000 results that should be retrieved, there is no way to get them all if Skip is not implemented in the library.
 
Last edited:

BowTieNeck

Member
Licensed User
Longtime User
First, thanks for a great library. It worked first time for me, very clear instructions.
I'd like my users to have the option to not receive notifications so I've created a Settings Activity where they can select a radio button to choose whether or not they get notifications.
To switch off notifications I've tried Parse.Unsubscribe("Channel1") and Parse.DisableNotifications followed by Parse.Unsubscribe("Channel1") but neither way seems to work.
I'm obviously missing something. What is it?
Thanks,
Chris
 

clarionero

Active Member
Licensed User
Longtime User
Hi. The last version of library is 1.4 but if i open the XML file it say version 1.2. Which is wrong?

Thanks

Rubén
 

touchsquid

Active Member
Licensed User
Longtime User
I love the work agraham does. The parse library is excellent, but seems to be missing the ParseUser object which I need for my app. Any chance that could be added?
 
Top