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,201
Last edited by a moderator:

stu14t

Active Member
Licensed User
Longtime User
Hi agraham

I sent you some beer money via Paypal for your excellent libraries. I wonder if you could answer my previous question about the ParseUser object.

Thanks from the Squid!

I'd be interested to see the functionality of PaseUser or PFUser added to this library. Should I add this to the wishlist?
 

mrodriguez

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

I have the same questions, specially 1) and 4)

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.

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
 

mrodriguez

Member
Licensed User
Longtime User
Hi, I have 2 questions about parse library that was posting by other member too.

a) 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.

b) 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.

Thanks
 

mrodriguez

Member
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:


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 ?

Derez, I'm trying to send push notification from one android device to another one. Could you do it? Can share the code?
Thanks
 

derez

Expert
Licensed User
Longtime User
send push notification from one android device to another one
what I do in my applications with parse is send notifications triggered by one user to all the users (example - update of an item in family tree).
I haven't sent from one device to only one other device, but it is possible - you have to know the user ID in parse.
 

mrodriguez

Member
Licensed User
Longtime User
what I do in my applications with parse is send notifications triggered by one user to all the users (example - update of an item in family tree).
I haven't sent from one device to only one other device, but it is possible - you have to know the user ID in parse.
\Hi,
what I do in my applications with parse is send notifications triggered by one user to all the users (example - update of an item in family tree).
I haven't sent from one device to only one other device, but it is possible - you have to know the user ID in parse.

Hi, that exactly what i need. One android device (mine) is the master, and the others android devices are the slaves (customers). Master device send notifications to slaves devices.
Have you done everything over b4a code (master device)? Can you share this part of code?
Or have you used parse java coud code to do that?

On other hand, can you send notificacion over a module service instead activity? I need to receive the information send by the push service in the background and in a silent way. Right now i can receive it with a notification and over an activity.
Thanks a lot.
 

derez

Expert
Licensed User
Longtime User
Here are some subs with the code relevant to push notification. You have also to enable push in your prject in parse site.
There is no master -slave relations, any device that sends a notification broadcasts it to all.
B4X:
Sub Process_Globals

Dim Parse As Parse
Dim push As ParsePush

End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("family.bal")

'parse
If FirstTime Then
    Parse.SetLoggingLevel(2147483647)
    Parse.EnableNotifications(FamilyNotification)
    Parse.Subscribe("Family", FamilyNotification)

    push.Initialize
    push.SetChannel("Family")
    push.SetExpirationTimeInterval(300)
   End If

End Sub

Sub delete_click
    push.SetMessage(Ft.Name & " " & Ft.Surname & " deleted")
    push.Send("push",2)
End Sub

Sub parse_add_item(k As Int)
Dim Addpo As ParseObject
Addpo.Initialize("Family")
p_item_common(k , Addpo)
End Sub

Sub p_item_common(k As Int, Npo As ParseObject)
...
    push.SetMessage(cur.GetString("Name") & " " & cur.GetString("Surname") & " updated")
...
push.Send("push",2)
...
End Sub

In manifest file I have this added:
B4X:
SetManifestAttribute("android:installLocation", "auto")
SetActivityAttribute(FamilyNotification, android:noHistory, "true")
SetActivityAttribute(Main, android:screenOrientation, "landscape")
SetActivityAttribute(FamilyNotification, android:screenOrientation, "unspecified")

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>)

I need to receive the information send by the push service in the background and in a silent way.
The way the notification is recieved is not controlled by the application or by parse, its the way android works. Can it be changed ? I don't know.
 
Last edited:

mrodriguez

Member
Licensed User
Longtime User
Here are some subs with the code relevant to push notification. You have also to enable push in your prject in parse site.
There is no master -slave relations, any device that sends a notification broadcasts it to all.
B4X:
Sub Process_Globals

Dim Parse As Parse
Dim push As ParsePush

End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("family.bal")

'parse
If FirstTime Then
    Parse.SetLoggingLevel(2147483647)
    Parse.EnableNotifications(FamilyNotification)
    Parse.Subscribe("Family", FamilyNotification)

    push.Initialize
    push.SetChannel("Family")
    push.SetExpirationTimeInterval(300)
   End If

End Sub

Sub delete_click
    push.SetMessage(Ft.Name & " " & Ft.Surname & " deleted")
    push.Send("push",2)
End Sub

Sub parse_add_item(k As Int)
Dim Addpo As ParseObject
Addpo.Initialize("Family")
p_item_common(k , Addpo)
End Sub

Sub p_item_common(k As Int, Npo As ParseObject)
...
    push.SetMessage(cur.GetString("Name") & " " & cur.GetString("Surname") & " updated")
...
push.Send("push",2)
...
End Sub

In manifest file I have this addes:
B4X:
SetManifestAttribute("android:installLocation", "auto")
SetActivityAttribute(FamilyNotification, android:noHistory, "true")
SetActivityAttribute(Main, android:screenOrientation, "landscape")
SetActivityAttribute(FamilyNotification, android:screenOrientation, "unspecified")

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>)


The way the notification is recieved is not controlled by the application or by parse, its the way android works. Can it be changed ? I don't know.

Thanks a lot!!!
 

mrodriguez

Member
Licensed User
Longtime User
Hi, it seems that parse can send push notification to a service and in a silent way.

The probem is that there is no Push.setData , just Push.SetMessage.
I hope that someone can add it to the library.

Customizing your Notifications
  • alert: the notification's message.
  • action:(Android only) the Intent should be fired when the push is received. If no title or alert values are specified, the Intent will be fired but no notification will appear to the user.
FROM: https://parse.com/questions/custom-handling-of-push-notification

public void pushText(View v)
{
TextView pushTextView = (TextView)findViewById(R.id.editText1);
String textToBePushed = pushTextView.getText().toString();
Toast.makeText(getApplicationContext(), "onClick()"+v.getId(), Toast.LENGTH_LONG).show();
ParsePush push = new ParsePush();
push.setMessage(textToBePushed);
//push.setPushToAndroid(true);
push.setChannel("mySecondChannel");

JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("action", "com.example.UPDATE_SCORE");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
push.setData(jsonObject);


push.sendInBackground();
}
========================

<service android:name="com.parse.PushService"></service>
<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>

<receiver android:name="com.example.mywordsapp.MyNotificationsReceiver">
<intent-filter>
<action android:name="com.example.UPDATE_SCORE" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />


</intent-filter>
</receiver>

================================= public void onReceive(Context context, Intent intent) {

Log.e(MY_NOTIFICATIONS_RECEIVER, "in onReceive()");
--
--
}

More links
http://developingonandroid.wordpres...-push-notifications-in-parse-a-deep-overview/

http://www.androidbook.com/akc/display?url=DisplayNoteIMPURL&reportId=4553&ownerUserId=android
 
Last edited:

QuentinLindh

Member
Licensed User
Longtime User
I am attempting to get the parse example up and running with the new parse1.7.0
The example compiles, installs on my device (nexus 7) but "stops working" before opening.
From the parse.com website I gather that 1.7.0 is pretty new. I wonder if anyone else is running this version of the with success?
Or Can anyone link me to an older version of the parse sdk that will work?
Thanks,
Quentin
UPDATE:
works fine, my problem was not making res.xml read only- it got deleted.
 
Last edited:

QuentinLindh

Member
Licensed User
Longtime User
I am attempting to get the parse example up and running with the new parse1.7.0
The example compiles, installs on my device (nexus 7) but "stops working" before opening.
From the parse.com website I gather that 1.7.0 is pretty new. I wonder if anyone else is running this version of the with success?
Or Can anyone link me to an older version of the parse sdk that will work?
Thanks,
Quentin
Update:
actually, it seems to work fine- my problem was that I did not make the res.xml file with the keys read only and it got deleted..
 

QuentinLindh

Member
Licensed User
Longtime User
I have a very basic question: Excuse me if it is dumb/basic I am new to both parse and b4a
I want to use parse backside to do a very simple thing, save and keep synced some set-points,
let's say 10 integers.
So I create a Parse object it and I put in my setpoints e.g. params.Put("setpoint1","5") ...
I can save it to the parse database, with params.Save("params",1)
This works fine, there it is in the parse dashboard, all very nice and easy.
Here is where I am stuck: I want to do 2 things
1: I want to update the object that is stored in the database, not add a new one, with a new unique objectID -- like update in SQL
2: I want to poll the server when the app loads and get the object into memory. -- can I use params.refresh to achieve this?
It seems like overkill to do a query where I just want to put and get data into a single object with fixed ID.
Seems like the most simple possible case but I'm not seeing how to do it.
Thanks,
Quentin
 

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
Hello,
please need some help to send push notification.
I follow your instruction, sign up in parse, create app, download SDK and rename it into ParseNative.jar, create res.xml and filled it with my appclientkey and appid and modified the androidmanifest.xml, as they mentioned here: https://parse.com/tutorials/android-push-notifications.
But, every time I start the app, it crash.
This is the log:

B4X:
LogCat connected to: 0607970a
--------- beginning of /dev/log/main
--------- beginning of /dev/log/system
ParseApplication.onCreate xml Id = 0
ParseApplication.onCreate xml Id = 2130903040
data null
data1 MYAPPLICATION ID
data2 MYAPPLICATION KEY

What do I do?
 
Top