October 15, 2018

Android Error: Failed to resolve: com.google.firebase

[Android Studio]

Issue:

I updated gradle to 4.4 in my Android app and added below firebase libraries to my app level build.gradle file

implementation 'com.google.firebase:firebase-core:16.0.0'


but while building the project, got the below error

Failed to resolve: com.google.firebase:firebase-core:16.0.0


Solution:
This is a maven issue. This issue is resolved after adding google() to repositories of allporjects in project level build.gradle file. Now the json looks like below.

allprojects {
    repositories {
        google()
        jcenter()
    }
}

August 26, 2018

How to run background service in Oracle MAF

In mobile apps, we often need some services to run in the background to do tasks like fetching or updating data from a server, sync local data with a server, invoking APIs etc.
In this post, we will see how to run a task in the background of a mobile app developed using Oracle MAF.

There is a default utility available in Oracle MAF to run java code in background threads which is MafExecutorService. It has a method execute() to run java runnable on a background thread in the context of the calling thread's MAF feature context. The syntax of the method is like

MafExecutorService.execute(new Runnable()
{
public void run()
{
         //Invoke your methods here     
}
});

If you update any data change events in the background, invoke below method to make it effective.

AdfmfJavaUtilities.flushDataChangeEvent();

June 16, 2018

Oracle Intelligent Bots: Get the user Geo location from the map

For few use cases like delivering a Pizza, it would be a great user experience to take user's current location directly from a Map instead of asking the user to type his address.

In this post, we will see how to capture the user location from a map in a chatbot developed in Oracle ChatBots.

Oracle bots provide a component "System.CommonResponse" which helps us here to get the location. Below is the snippet to get the location.

----------------------------------------------------------------------------------------------------
 userLocation:
    component: "System.CommonResponse"
    properties:
      processUserMessage: true
      keepTurn: false
      variable: "loc"
      nlpResultVariable:
      maxPrompts:
      translate:
      metadata:
        responseItems: 
        - type: "text"
          text: "OK.. Please provide your address to deliver the Pizza?"
          iteratorVariable:
          separateBubbles: false
          rendered: 
        globalActions:
        - label: "Send Location"
          type: "location" 
    transitions:
      actions:
        locationReceived: "locMapReceived"
        textReceived: "locTextReceived"

----------------------------------------------------------------------------------------------------

The above code results as below image.
When the user clicks on the "Send Location" button, it will open the map application. The user can select current or any other location and submit. Once the user submits the location, the bot will receive a JSON into the variable assigned for it which is "loc" in the above example and invokes state assigned to the action "locationReceived". The JSON looks like as below. 

{"latitude":17.727758609852,"title":"Learning's Location","url":"<url of the map>","longitude":83.287353515625}

The JSON contains, latitude, longitude, title of the location on the map and the direct url to the selected location.

In the above example we have another action "textReceived" which helps to handle if user inputs text instead of selection on map.

Note: While implementing this, please check if your client application supports this feature and maps. I tested this with FB and Test console.