Alfresco
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.
android:usesCleartextTraffic="true"
Step 3: Add the following code to build.gradle(Module: app) file.
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'
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 moreThe technology has been a pioneer in speeding up the data analysis of customers for enterprises.
17 Jul 2024
Learn about Alfresco development and its benefits for businesses. Discover how leveraging Alfresco can enhance efficiency and collaboration.
17 Jul 2024
Mastering Alfresco Development: Essential Tips for Success in ECM Solutions” provides crucial insights and strategies for developers to excel in…
17 Jul 2024
401, One World West, Nr. Ambli T-Junction 200, S P Ring Road, Bopal, Ahmedabad, Gujarat 380058
Kemp House 160 City Road, London, United Kingdom EC1V 2NX
Nürnberger Str. 46 90579 Langenzenn Deutschland
Level 36 Riparian Plaza, 71 Eagle Street, Brisbane, QLD 4000
4411 Suwanee Dam road, Bld. 300 Ste. 350 Suwanee GA, 30024
Cube Work Space, 24 Hans Strijdom Avenue, Cape Town
B 503 Sama Tower, Sheikh Zayed Road, United Arab Emirates
34 Applegrove Ct. Brampton ON L6R 2Y8
We use cookies to improve your browsing experience.
OKAYThis website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.
If you disable this cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.