Enable Dark Mode!
how-to-integrate-odoo-with-android.png
By: Muhammed Nishad

How to Integrate Odoo with Android

Technical

Odoo is a virtual jungle with immense possibilities of customization, to deal with the diverse territories of an organization or industry. The Open Source ERP constantly expand its effectiveness via third-party applications. The rich API library and web administrations in Odoo help in bringing qualitative innovations every now and then. The android integrations with Odoo, facilitates the new generation business, a way to modernize, combine, and facilitate the business operations in new dimensions.


Here I’m Going to discuss creating an Android application, that communicates with odoo server.I’m doing this tutorial in Android Studio.


For Android Studio Installation, 


you can Visit here: https://developer.android.com/studio/install


First of All, let’s Create a new project: 

You can go to file > new > new project Or Do it from this window


how-to-integrate-odoo-with-android-1-cybrosys

Create a new project by filling up this window.


how-to-integrate-odoo-with-android-2-cybrosys

The next thing we have to do is, downloading and installing the OOG Box API

This can get a bit technical.

Firstly, you have to go to https://github.com/oogbox/odoo-mobile-api

Then a page will appear like the below image

how-to-integrate-odoo-with-android-3-cybrosys

Click the clone or download button, and choose Download ZIP

how-to-integrate-odoo-with-android-4-cybrosys

Now extract this file to a folder you like, and  it will have a name like “odoo-mobile-api-1.0.0

Now go to your project location and create a new folder named libraries. And paste the extracted folder to that folder.

Now, the directory structure will look somewhat like below:

how-to-integrate-odoo-with-android-5-cybrosys

In the next step, we have to add this to settings Gradle, Try the below code

include ':app'
include 'libraries:odoo-mobile-api-1.0.0'

Now we are partially set to get into the code, But there is one more important thing we have to do i.e. including the OOG Box API in your apps build.gradle


dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
}
implementation 'com.oogbox.api:odoo:1.0.1'

Now,  Let’s get coded:

Here I create an application that simply lets the user login to odoo.

So I have created a login page, and I have set the host to mydomain.com

Let’s see the code.

These are my imports from OOG Box.api

import oogbox.api.odoo.OdooClient;
import oogbox.api.odoo.OdooUser;
import oogbox.api.odoo.client.AuthError;
import oogbox.api.odoo.client.OdooVersion;
import oogbox.api.odoo.client.listeners.AuthenticateListener;
import oogbox.api.odoo.client.helper.OdooErrorException;
import oogbox.api.odoo.client.listeners.OdooErrorListener;
import oogbox.api.odoo.client.listeners.OdooConnectListener;

And we can set up the login by the below code.

client = new OdooClient.Builder(getApplicationContext())
.setHost("http://"+ip)
.setErrorListener(new OdooErrorListener() {
@Override public void onError(OdooErrorException error) {
Toast.makeText(getApplicationContext(),"Error",Toast.LENGTH_LONG).show();
// Error exception with detail of errors } })
// Success connection
.setConnectListener(new OdooConnectListener() { @Override public void onConnected(OdooVersion version) {
ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_spinner_dropdown_item, databases);
List<String> databases = client.getDatabases(); dataBases = (Spinner)findViewById(R.id.spinnerDataBases); dataBases.setAdapter(listAdapter);
}).build();
}

In the above code, I have established a connection to the server and fetched the names of Odoo databases and put across in a spinner.

Now let’s see how the login works.

buttonLogin.setOnClickListener(new View.OnClickListener() {
@Override
AuthenticateListener loginCallback = new AuthenticateListener() {
public void onClick(View v) {
public void onLoginSuccess(OdooUser user) {
@Override
Intent intent = new Intent(getApplicationContext(),HomeActivity.class);
intent.putExtra("sessionId",user.sessionId); startActivity(intent);
Toast.makeText(getApplicationContext(),error.toString(),Toast.LENGTH_LONG).show();
} @Override public void onLoginFail(AuthError error) { }
String password = editPassword.getText().toString();
}; String email = editEmail.getText().toString();
});
client.authenticate(email,password,dataBases.getSelectedItem().toString(),loginCallback);
}

Here, I have a button named button Login,  I have set an onclick method to it.

When a click is performed, the username and the password along with the database selected from the spinner is sent to Odoo. And If the username and password get correct, It will return an Odoo user object. You can get the session id from this object and you can use it for odooClient.setSession() method.

Now we can use the Odoo object for any communication with the server just like the volley does.


If you need any assistance in odoo, we are online, please chat with us.



5
Comments

Imran

There is also a framework called Odoo Mobile Framework. I have tried it but found a lot of issues and I was not able to get it to work properly. I have discussed with an < a href="https://www.odooconsultant.com/">Odoo Consultant and he was unable to complete my doubt. If the author has any experience with Odoo framework. Let me know.

30/04/2020

-

4:43AM

Ram

This URL not working ***https://github.com/oogbox/odoo-mobile-api***. And I'm facing session expired issues. it working odoo version 10 but 12 and 13 not working. It throwing "SESSION EXPIRED". Is this library working for odoo 13..? Thanks in adv.

29/10/2020

-

11:23PM

Mansi Shah

Is this API still available?? I am working on this API but find Some issues. If you are still working with the same please do reply asap. Thank you, Mansi

26/12/2019

-

12:30AM

Parimal

Sir, I want to work on this API. Please Guide me how can I fully developed the Odoo HelpDesk module. Please help me. Thanking you Parimal

22/08/2020

-

1:26PM

Sahil

Is this library available for odoo v13?

17/09/2019

-

9:35PM



Leave a comment



whatsapp
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message