Skip to content

caraus/Lifelog-Android-Library

 
 

Repository files navigation

#LifeLog Android Library This is an Android (not pure java) wrapper for the LifeLog Web API.

##QuickStart I will upload this maven & jcenter soon, bear with the cumbersome process of manually downloading source and adding it till then

###Initialise In your Application class, inside the onCreate body, add this

LifeLog.initialise("clientid", "secret", "https://callbackurl.com");

Replace clientid, secret and callbackurl with your respective values of the app that you have registered on LifeLog.

###Login and authentication ####Login To log the user in for the first time, use this simple static method

LifeLog.doLogin(MainActivity.this)

Note that, after login is completed, we will return back to same activity. Internally, doLogin makes a startActivityForResult call. Handle the returning user like this

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == LifeLog.LOGINACTIVITY_REQUEST_CODE) {
            //we are logged in, do what you please now
            Toast.makeText(this, "User authenticated", Toast.LENGTH_SHORT).show();
        }
    }

####Checking Authentication state You would want to check if the user is authenticated or not. Even if he is, we may need to refresh the auth token. Again, simple code for that.

LifeLog.checkAuthentication(this, new LifeLog.OnAuthenticationChecked() {
    @Override
    public void onAuthChecked(boolean authenticated) {
        if (authenticated) {
            //User is authenticated, we can do API requests now
        } else {
            //User is not authenticated. Make him login (or whatever suits your app's flow)
            //LifeLog.doLogin(MainActivity.this);
        }
    }
});

###API Requests ####Location endpoint Create an object of LifeLogLocationAPI using one of the two prepareRequest methods. One allows you to specify start and end time. Other doesn't. You can set either of start or end time to be null as well.

The data fetching actually starts when get is called. After the data is fetched, the onLocationFetched callback is hit. A List<> of LifeLogLocation objects are at your disposal.

LifeLogLocationAPI llLocation = LifeLogLocationAPI.prepareRequest(500);
    llLocation.get(MainActivity.this, new LifeLogLocationAPI.OnLocationFetched() {
        @Override
        public void onLocationFetched(ArrayList<LifeLogLocationAPI.LifeLogLocation> locations) {
            for (LifeLogLocationAPI.LifeLogLocation loc : locations) {
                String id = loc.getId();
                Calendar startTime = loc.getStartTime();
                //continue likewise
            }
        }
    });

About

An Android Library/API to access Sony Lifelog palatform.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%