Alfresco

How to Integrate Alfresco Login API With Standalone Native Android Application

Alfresco Enterprise Content Management (ECM) and Business Process Management (BPM) tool, widely used as a web application. With the increasing involvement of mobile devices in business use cases, the dependency of mobile devices in daily work has also been increased. As, we may be aware of the Alfresco Content Service Android Application available on the playstore, but sometimes client requirement leads us to develop a standalone application for the specific purpose like scanning barcodes from the mobile device and storing it to the Alfresco Repository or some other specific requirement.

Alfresco is based on RESTful APIs and can be communicated with other platforms via REST APIs easily. We can use Alfresco login REST API to integrate it with Android Application. This blog is a step-by-step guide to integrate Alfresco login API with Android.

Create one New Project in Android Studio and follow below steps.

Step 1: Add the following code inside activity_main.xml


Step 2: Edit AndroidManifest.xml.

    • Inside ….. add following line
      
      
    • Inside add following line
       android:usesCleartextTraffic="true"
    • Inside …… add foolowing line
      
      

Step 3: Add the following code to build.gradle(Module: app) file.

  • Inside dependencies{} add following lines :
     implementation('com.omertron:themoviedbapi:4.2') {
    exclude group: 'org.apache.httpcomponents', module: 'httpclient'
    exclude module: 'junit'
    }
    implementation 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
    implementation 'commons-io:commons-io:2.4'
  • Inside android{} add the following line :
     useLibrary 'org.apache.http.legacy'

Step 4: Add the following code inside MainActivity.java

 public class MainActivity extends AppCompatActivity {
    static EditText et_login_siteurl, et_login_username, et_login_password;
    Button btn_login;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        et_login_siteurl = (EditText)findViewById(R.id.et_login_siteurl);
        et_login_username = (EditText)findViewById(R.id.et_login_username);
        et_login_password = (EditText)findViewById(R.id.et_login_password);
        btn_login = (Button)findViewById(R.id.btn_login);
        btn_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                try {
                    userLogin();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
    public void userLogin(){
        final String siteurl = et_login_siteurl.getText().toString();
        final String username = et_login_username.getText().toString();
        final String password = et_login_password.getText().toString();
        UserLogin u = new UserLogin();
        u.execute("https://"+siteurl+"/alfresco/service/api/login?u="+username+"&pw="+password+"&format=json");
    }
    class UserLogin extends AsyncTask{
        @Override
        protected String doInBackground(String... params) {
            try{
                HttpClient httpclient;
                httpclient = new DefaultHttpClient();
                HttpResponse response;
                String responseString = null;
                JSONObject jsonReader = null;
                response = httpclient.execute(new HttpGet(params[0]));
                StatusLine statusLine = response.getStatusLine();
                if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
                    ByteArrayOutputStream out = new ByteArrayOutputStream();
                    response.getEntity().writeTo(out);
                    out.close();
                    responseString = out.toString();
                    Log.d("------ResponseString--", responseString);
                    jsonReader = new JSONObject(responseString);
                    Intent i = new Intent(MainActivity.this, NextActivity.class);
	    //NextActivity.class shows the next screen you want to go 		    //after login
                    startActivity(i);
                }
            }catch(Exception e){
                    e.printStackTrace();
            }
            return null;
        }
    }
}

Above is the View of App created by above code. In the Site Url section, add the server URL and username and password in the App and click on the Login button which will redirect the App to the next page.

If you have any questions or feedback, feel free to contact us or comment on this blog.

Step-by-Step Guide to Add QR Code to Document in Alfresco

Read more

Transform Your Business With Digital Enterprise Solutions

Contact us

Our Offices

AHMEDABAD, INDIA

401, One World West, Nr. Ambli T-Junction 200, S P Ring Road, Bopal, Ahmedabad, Gujarat 380058

UK

Kemp House 160 City Road, London, United Kingdom EC1V 2NX

GERMANY

Nürnberger Str. 46 90579 Langenzenn Deutschland

AUSTRALIA

Level 36 Riparian Plaza, 71 Eagle Street, Brisbane, QLD 4000

USA

4411 Suwanee Dam road, Bld. 300 Ste. 350 Suwanee GA, 30024

SOUTH AFRICA

Cube Work Space, 24 Hans Strijdom Avenue, Cape Town

Mahindra DUBAI, UAE

B 503 Sama Tower, Sheikh Zayed Road, United Arab Emirates

CANADA

34 Applegrove Ct. Brampton ON L6R 2Y8