Portal Organizational Info

The purpose of this sample is to show how to create UserCredentials and a Portal object, and then use these to log in to a portal and fetch information about the portal and the organization.


  • Portal API
  • User Credentials
  • Simple Async Task
  • Fetch Organization Thumbnail

Sample Design

This sample has one activity, OrganizationInfoActivity, which executes an AsyncTask to do all the work. A private class OrgInfoAsyncTask extends AsyncTask and overrides the following methods:

  • The preExecute() method displays a progress dialog on the UI thread.
  • The doInBackground() method, which runs on a background thread, logs in to the server and fetches information about the portal and organization. It also checks if there is an organization thumbnail and if so fetches it.
  • The onPostExecute() method then displays the information on the UI thread.

A Portal object is created using the constructor which takes portal URL and credentials. The fetchPortalInfo() method is used to log in to the portal. This returns a PortalInfo object that contains most of the portal and organization info. However, the organization thumbnail (if any) must be fetched by calling fetchOrganizationThumbnail(). The thumbnail data is converted to a BitmapDrawable for display.

Sample Code

package com.esri.arcgis.samples.organizationinfo;

import java.io.ByteArrayInputStream;

import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.drawable.BitmapDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.esri.core.geometry.Envelope;
import com.esri.core.io.UserCredentials;
import com.esri.core.portal.Portal;
import com.esri.core.portal.PortalInfo;

 * The purpose of this sample is to show how to create UserCredentials and a
 * Portal object, and then use these to log in to a portal and fetch information
 * about the portal and the organization.
public class OrganizationInfoActivity extends Activity {

  private static final String TAG = "OrganizationInfoActivity";

  private static final String URL = "http://arcgis.com";

  private static final String USER_NAME = "democsf";

  private static final String PASSWORD = "devdemo";

  ProgressDialog mProgressDialog;

  byte[] mThumbnailData;

  protected void onCreate(Bundle savedInstanceState) {

    // Setup progress dialog
    mProgressDialog = new ProgressDialog(this) {
      public void onBackPressed() {
        // Back key pressed - dismiss the dialog and finish the activity

    // Execute an async task to fetch and display organization info
    new OrgInfoAsyncTask().execute();

   * This class provides an AsyncTask that fetches organization info from the
   * server on a background thread and displays it on the UI thread.
  private class OrgInfoAsyncTask extends AsyncTask<Void, Void, PortalInfo> {
    private Exception mException;

    public OrgInfoAsyncTask() {

    protected void onPreExecute() {
      // Display progress dialog on UI thread

    protected PortalInfo doInBackground(Void... params) {
      // Fetch organization info on background thread
      mException = null;
      PortalInfo portalInfo = null;

      // Create UserCredentials with USER_NAME and PASSWORD. Anonymous
      // login is also possible.
      UserCredentials credentials = new UserCredentials();
      credentials.setUserAccount(USER_NAME, PASSWORD);

      // Create a Portal object
      Portal portal = new Portal(URL, credentials);

      try {
        // Fetch portal info from server. This logs in with the
        // credentials set above
        portalInfo = portal.fetchPortalInfo();

        // Fetch organization thumbnail (if any) from server
        if (portalInfo.getOrganizationThumbnailFileName() != null) {
          mThumbnailData = portalInfo.fetchOrganizationThumbnail();
      } catch (Exception e) {
        mException = e;
      return portalInfo;

    protected void onPostExecute(PortalInfo portalInfo) {
      // Display results on UI thread
      if (mException != null) {
        Log.w(TAG, mException.toString());
        Toast.makeText(OrganizationInfoActivity.this, getString(R.string.fetchDataFailed), Toast.LENGTH_LONG).show();

      if (portalInfo != null) {
        TextView textView;

        textView = (TextView) findViewById(R.id.orgNameTextView);

        // Organization description needs a WebView because it contains
        // markup code
        WebView webView = (WebView) findViewById(R.id.orgDescriptionWebView);
        webView.loadDataWithBaseURL(null, portalInfo.getOrganizationDescription(), "text/html", "utf-8", null);

        textView = (TextView) findViewById(R.id.orgIdTextView);

        Envelope env = new Envelope();
        textView = (TextView) findViewById(R.id.extentTextView);

        // build extent text
        StringBuilder extentXY = new StringBuilder();
        extentXY.append(" ");
        extentXY.append(" ");
        extentXY.append(" ");


        textView = (TextView) findViewById(R.id.isSharedTextView);

        textView = (TextView) findViewById(R.id.basemapTextView);

        if (mThumbnailData != null) {
          textView = (TextView) findViewById(R.id.thumbnailFilenameTextView);

          ByteArrayInputStream bytes = new ByteArrayInputStream(mThumbnailData);
          BitmapDrawable bmd = new BitmapDrawable(getResources(), bytes);
          if (bmd != null) {
            ImageView imageView = (ImageView) findViewById(R.id.orgImageView);


Feedback on this topic?