mercadolibre/developers-android_sdk

Name: developers-android_sdk

Owner: MercadoLibre

Description: Android SDK

Created: 2016-02-05 17:04:08.0

Updated: 2018-05-23 20:34:20.0

Pushed: 2017-02-13 12:05:42.0

Homepage: null

Size: 15360

Language: Java

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

MercadoLibre's Android SDK

This is the official Android SDK for MercadoLibre's Platform.

How can I install it?
Android Studio

Add this line to yout app's build.gradle inside the dependenciessection:

ndencies {
compile 'com.mercadolibre.android.sdk:mercadolibre_android_sdk:1.0.0'

ProGuard

If you're planning on optimizing your app with ProGuard, make sure that you exclude the MercadoLibre bindings. You can do this by adding the following to your app's proguard.cfg file:

 -keep class com.mercadolibre.** { *; }
How do I start using it?

In order for the SDK to work, you need to add two String resources in your strings.xml file:

<string name="meli_app_id">[Application identifier]</string>

and

<string name="meli_redirect_uri">[Redirect URI]</string>

Where:

Then you need to link this resources in the AndroidManifest.xml file of your application as follow:

    <meta-data
        android:name="com.mercadolibre.android.sdk.ApplicationId"
        android:value="@string/meli_app_id" />

    <meta-data
        android:name="com.mercadolibre.android.sdk.RedirectUrl"
        android:value="@string/meli_redirect_uri" />

*NOTE: if you fail to provide any of these attributes or the proper declaration in the AndroidManifest.xml file, the library will throw an exception on startup.

Also, you need to declare the <uses-permission android:name="android.permission.INTERNET" /> permission in your AndroidManifest.xml file and add the MercadoLibreActivity as described below.

Initialize the SDK

The first thing you need to do in order to use any of the features provided by the SDK is initialize it. You can do this by calling

  `Meli.initializeSDK(context);`
Authorizing your application with the user

The SDK provides functionallity to authorize your users to use your application with the MercadoLibre credentials. In order to do that, you need to follow these steps:

1 - (Mandatory) declare the MercadoLibreActivity in your AndroidManifest.xml. You can do it like this (recommended):

      <activity
        android:name="com.mercadolibre.android.sdk.MercadoLibreActivity"
        android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Translucent.NoTitleBar" />

2 - Then you need to call the Meli method for login:

              Meli.startLogin(Activity activityClient, int requestCode);

from within your Activity.

Making GET calls

You have two basic ways to do a GET call:

Anonymous
esponse r = Meli.get("/users/123");
or
.asyncGet("/users/" + getUserID(),apiRequestListener);
Authenticated
esponse r = Meli.getAuth("/users/123/addresses", Meli.getCurrentIdentity(context));
or
.asyncGetAuth("/users/" + getUserID() + "/addresses",Meli.getCurrentIdentity(context),apiRequestListener);
Making POST calls
esponse r = Meli.post("/items", bodyJsonAsString , Meli.getCurrentIdentity(context));
or
.asyncPost("/items", bodyJsonAsString,Meli.getCurrentIdentity(context),apiRequestListener);
Making PUT calls
esponse r = Meli.put("/items", bodyJsonAsString , Meli.getCurrentIdentity(context));
or
i.asyncPut("/items/MLA608718494",bodyJsonAsString,Meli.getCurrentIdentity(context),apiRequestListener);
Making DELETE calls
esponse r = Meli.delete("/items", bodyJsonAsString , Meli.getCurrentIdentity(context));
or
esponse r = Meli.asyncDelete("/items", bodyJsonAsString , Meli.getCurrentIdentity(context), apiRequestListener);
Asynchronous calls

Make sure to implement ` ApiRequestListener` on any component that will receive results from the calls.

Those results will be notified to the listener supplied through the callback method

 onRequestProcessed(@HttpRequestParameters.MeliHttpVerbs int requestCode, ApiResponse payload);
Examples

Within the code in the Github repository, there is an example project that contains examples of how to use the SDK.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.