Message:

Android (22 posts)

Since Backendless does not have native APIs to download files, today we’ll talk about how to implement this function in your Android application. In order to do that, we’ll need to combine Backendless file listing API and android.app.DownloadManager. There are several alternatives to this approach, but the selected one requires less code to write and has a well-thought structure.

Once a developer uploads files to the Backendless Files system, each file gets a public URL which can either be obtained using the Backendless Console or calculated using the following URL scheme:

publicURL 1024x472 - How to download a file stored in Backendless with your Android appThis public URI is the full path to the file in your Backendless file system. Directory listing API returns a list of the  FileInfo objects representing the files located in the directory, where each element in the collection contains the following properties:

  • name  – the name of the file or directory without any path information
  • public URL  – absolute URL of the file or directory
  • URL  – relative URL of the file or directory starting from the root of the file storage
  • created on  – a timestamp indicating when the file or directory was created

In this guide, we’ll be dealing with listing and downloading all the files with the  .html  extension in the /web  folder located in the root directory of your Backendless file system.

As for the Android app itself, we’ll need to:

  1. Define the  INTERNET and WRITE_EXTERNAL_STORAGE  permissions in Android manifest:
  2. Create a method to list all files in the directory:

    In this code sample, allFiles is a variable, which stores the results of the listing operation, and filesList is a TextView class where we show all the existing files.

    When the listing process is finished, we can start the download.

  3. Create a method which gets the public URIs of each file in a directory and will download these files in series:

    That’s all we need to make it work on Android devices with SDK < 23. On devices with SDK 23+, we’ll have application users to grant the permission to use their device storage. A method to check the device SDK and to ask for permission (if necessary) may look like this (in our code sample it is called before the download starts in Step 3):

We need to call this method in download method of your download activity  class. The result of the user choice should be handled in a separate callback, the same callback the download process should be restored:

Where downloadFiles is a button to start the download.

 The whole test app interface will look like this:

mainActivity - How to download a file stored in Backendless with your Android app

Selection 154 - How to download a file stored in Backendless with your Android app

Once you click the ALLOW button, the download process will be started.

Selection 155 - How to download a file stored in Backendless with your Android app

That’s it! The archive with this application can be found here: https://drive.google.com/open?id=1A4Mx3UEWK_ckgaSjaw0TWU5OvVq4ocLY

Don’t forget to add your Backendless AppId and Android API key in the  Defaults class.

Thanks for reading this post, hope you like it! 

All available APIs for creating, updating and deleting objects in the Backendless database operate on single objects. It means when you need to store multiple objects in the database, each object requires a separate API call. This increases the number of API calls your app makes. While it is great for us (hey, our billing is based on the API calls), it is not that great for your app as it results in longer processing times and substandard user experience. Starting today, with the release of Backendless version 4.5.0 we’re introducing the new APIs which will allow you to create, update or delete multiple objects with a single API call.

Bulk Create

Saving multiple new objects in the database is now as simple as passing an array of objects to the server. The server responds with a collection of objectId values (which, for example, can be used in the createRelation  API). The bulk create API is supported in all SDKs as well as the REST interface.

Bulk Update

To update objects in the database, the API accepts a condition (where clause) which identifies a group of objects. In addition to the condition, the client must also provide an object containing the changes which should be applies to the selected objects.

Bulk Delete

Similar to “Bulk Update”, this API receives a condition which identifies a group of objects to be deleted.

All of the APIs can be extended using custom business logic’s before/after events.

You can find the documentation for these APIs in the developer guides:

Performing a calculation on a group of database objects may be a complex task. For example, to calculate the sum of all orders for a customer would require retrieving all customer’s orders, iterating over them to calculate the mathematical sum of all amounts. This was yesterday! As of Backendless 4.4.0, you can use aggregate functions to calculate the average, sum, maximum and minimum values for a collection of objects without retrieving them from the server. Additionally, the system supports calculating object count for all records in the database or a record subset.

To use an aggregate function, simply request a property in a data retrieval request in the following format (the example below is for calculating the sum for the orderAmount  column):

The returned object includes the sum  property with the calculated value:

The name of the property can be modified by assigning an alias (using %20  to replace the spaces in the URL):

The result contains a value for the property named after the alias:

Grouping Results

Results can be grouped by a column. The column could be either in the same table or a related one. For example, the following request retrieves the sum of all orders grouped by related country:

Unlike the response above, the result for this query includes a collection of objects, each containing the sum for a related country:

It is also possible to apply a filter on the grouped values. This can be done using the having  clause. For example, the request below retrieves only the groups of countries where the total order amount is greater than 10000:

For more information about aggregate functions see the Backendless API documentation:

If you’re starting an Android project with Backendless and import our SDK library from Maven, please pay attention to the version number of the library. We have published a beta version of the 4.0 SDK into Maven central. When referencing Backendless in Android Studio, version 4 is the default one to popup. Unless you’re building with Backendless version 4 (which will be the default backend in the Cloud very soon), make sure to reference version 3.0.25 of the library as shown in the screenshots below:

Continue reading

google signin backendless - Google Sign in for your Backendless AppWe supported Google Sign in for a while, however, the feature was not properly documented. Not anymore )) The documentation has been updated for Android and iOS SDKs. Using the “Login with Google” function, an app can provide a way for the users to login using their Google credentials. Once a user is authenticated, Backendless creates an internal account and starts a logged-in session.

See Backendless documentation for details:

Android SDK

iOS SDK

The recording of the “Push Notifications” webinar which we conducted earlier this month is now available in our YouTube channel. You watch the webinar below or on the Webinars page on our website. In the webinar we reviewed the process of setting up an Android and an iOS apps as well as the backend to be able to register device and receive push notifications.

We conducted a webinar titled “Backendless Core Concepts” for ex-Parses last week. A recording of the webinar is now available. The video should be helpful not only if you’re coming from Parse, but for anyone who is starting their journey with Backendless. The webinar reviewed the concepts of Backendless User and Data services. Specifically, we focused on:

  • user properties
  • setting up user relations
  • registering a user
  • registering a user with custom properties
  • configuring a data model
  • code-driven schema creation
  • data relations
  • a brief overview of Cloud Code

In my previous post I reviewed the user registration API. Now that you know how to use the registration API and have a registered user, the next step is to review the login functionality. The video below focuses on the apps’ login screen and the Backendless Login API.

In the video below I review the code for the User Registration screen of the RestaurantToGo sample app. Additionally, I discuss the usage of the Backendless Registration API. In the previous post and video, I reviewed the process of setting up the development environment for the application.

Whether you develop with IntelliJ IDEA, Eclipse or Android Studio, the Backendless library (jar) for Java/Android must be referenced as a dependency. The library includes all the APIs which provide access to the backend functionality. The library is deployed to the centralized Maven repository which makes it trivial to import it to any Backendless-powered app. Below are the instructions for referencing it in Android Studio:

Continue reading

Find us in facebook