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
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
This is the official Android SDK for MercadoLibre's Platform.
Add this line to yout app's build.gradle
inside the dependencies
section:
ndencies {
compile 'com.mercadolibre.android.sdk:mercadolibre_android_sdk:1.0.0'
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.** { *; }
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.
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);`
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.
The activityClient Activity is mandatory and will receive the callback response once that the user agrees (or reject) the usage of the application. This will happen in the Activity's
protected void onActivityResult(int requestCode, int resultCode, Intent data);
method. If the resultCode is Activity.RESULT_OK
, then the granted credentials will be available via the Identity object provided by the
Meli.getCurrentIdentity();
method.
You have two basic ways to do a GET call:
esponse r = Meli.get("/users/123");
or
.asyncGet("/users/" + getUserID(),apiRequestListener);
esponse r = Meli.getAuth("/users/123/addresses", Meli.getCurrentIdentity(context));
or
.asyncGetAuth("/users/" + getUserID() + "/addresses",Meli.getCurrentIdentity(context),apiRequestListener);
esponse r = Meli.post("/items", bodyJsonAsString , Meli.getCurrentIdentity(context));
or
.asyncPost("/items", bodyJsonAsString,Meli.getCurrentIdentity(context),apiRequestListener);
esponse r = Meli.put("/items", bodyJsonAsString , Meli.getCurrentIdentity(context));
or
i.asyncPut("/items/MLA608718494",bodyJsonAsString,Meli.getCurrentIdentity(context),apiRequestListener);
esponse r = Meli.delete("/items", bodyJsonAsString , Meli.getCurrentIdentity(context));
or
esponse r = Meli.asyncDelete("/items", bodyJsonAsString , Meli.getCurrentIdentity(context), apiRequestListener);
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);
Within the code in the Github repository, there is an example project that contains examples of how to use the SDK.