public class

OAuthView

extends WebView
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.AbsoluteLayout
         ↳ android.webkit.WebView
           ↳ com.esri.android.oauth.OAuthView

Class Overview

OAuthView extends Android's WebView and its purpose is to present a web page hosted on ArcGIS.com or ArcGIS portal that allows users to authorize the Android app you are writing to access resources on ArcGIS.com or ArcGIS portal. Before you can use OAuthView, you need a client ID. In order to get a client ID, you must register your app at ArcGIS.com or your organization's portal. You can create an OAuthView using Java code, or by Android layout xml.

XML usage:

 
 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   <com.esri.android.oauth.OAuthView
     android:id="@+id/oauthview"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     clientid="clientID"
     portalurl="https://arcgis.com" />
 />
 
 
Note that AlertDialog should be avoided because on some devices soft keyboard may not show up if WebView, which OAuthView extends, is put in an AlertDialog. Also note that if your dialog only shows the title but not the web page, consider nesting OAuthView in a FrameLayout before putting it in the dialog as in the above XML snippet.

Java Usage: OAuthView view = new OAuthView(context, portalURL, clientid, listener);

 
 OAuthView view = new OAuthView(this, PORTALURL, clientID, new CallbackListener() {
 
   public void onError(Throwable e) {        
   }
 
   public void onCallback(UserCredentials credentials) {
     MapView map = new MapView(context, url, credentials, null, null);
   }
 });
 
 
Upon successful authentication, the callback listener you provide would be invoked with a UserCredentials, which can be use to access WebMap or other resources on ArcGIS.com or portal. Note that if you use XML to create an OAuthView, you must explicitly call the setCallbackListener to register your listener.

You may receive an SslError if your organization uses private SSL certificate. To avoid such error make sure you install the SSL certificate on your Android devices first.

Optionally, define the following string values in res/values/strings.xml to customize the http authentication request dialog:

 
 <string name="ags_http_auth_request_dialog_title">Authentication Required</string>
 <string name="ags_http_auth_request_dialog_username_hint">Username</string>
 <string name="ags_http_auth_request_dialog_password_hint">Password</string>
 <string name="ags_http_auth_request_dialog_button1">Log in</string>
 <string name="ags_http_auth_request_dialog_button2">Cancel</string>
 <string name="oauthview_email_subject">Technical support</string>
 <string name="oauthview_email_body">What's your problem?</string>
 
 

Summary

Nested Classes
interface OAuthView.OnSslErrorListener  
[Expand]
Inherited Constants
From class android.webkit.WebView
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
OAuthView(Context context, String portalUrl, String clientId, CallbackListener<UserCredentials> listener)
Construct a new OAuthView with a portal URL, client ID and callback listener.
OAuthView(Context context, String portalUrl, String clientId, int expiration, CallbackListener<UserCredentials> listener)
Construct a new OAuthView with a portal URL, client ID, expiration time and callback listener.
OAuthView(Context context, AttributeSet attrs)
This constructor is called when the OAuthView object is being inflated from XML.
OAuthView(Context context, AttributeSet attrs, int defStyle)
This constructor is called when the OAuthView object is being inflated from XML.
Public Methods
void refresh()
refresh the web page.
void setCallbackListener(CallbackListener<UserCredentials> listener)
Registers a CallbackListener on the OAuthView.
void setClientId(String clientId)
Sets client Id.
void setExpiration(int length)
Sets refresh token expiration time in minutes.
void setOnSslErrorListener(OAuthView.OnSslErrorListener listener)
Registers a OnSslErrorListener on the OAuthView.
void setPortalUrl(String url)
Sets portal url.
void setappID(String appID)
This method is deprecated. in 10.2.2, use setClientId(String) instead
[Expand]
Inherited Methods
From class android.webkit.WebView
From class android.widget.AbsoluteLayout
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.view.ViewTreeObserver.OnGlobalFocusChangeListener
From interface android.view.ViewGroup.OnHierarchyChangeListener
From interface android.view.ViewParent
From interface android.view.ViewManager
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource

Public Constructors

public OAuthView (Context context, String portalUrl, String clientId, CallbackListener<UserCredentials> listener)

Construct a new OAuthView with a portal URL, client ID and callback listener.

Parameters
context Context: a Context object
portalUrl String: portal URL
clientId String: client Id
listener CallbackListener: callback listener

public OAuthView (Context context, String portalUrl, String clientId, int expiration, CallbackListener<UserCredentials> listener)

Construct a new OAuthView with a portal URL, client ID, expiration time and callback listener. Note that org admins can specify the max validity period of tokens for their org that supercedes the expiration parameter. A permanent refresh_token can be requested by specifying expiration=-1

Parameters
context Context: a Context object
portalUrl String: portal URL
clientId String: client Id
expiration int: expiration time in minute for refresh token
listener CallbackListener: callback listener

public OAuthView (Context context, AttributeSet attrs)

This constructor is called when the OAuthView object is being inflated from XML.

Parameters
context Context: a Context object
attrs AttributeSet: The attributes of the XML tag used to inflate the MapView

public OAuthView (Context context, AttributeSet attrs, int defStyle)

This constructor is called when the OAuthView object is being inflated from XML.

Parameters
context Context: a Context object
attrs AttributeSet: The attributes of the XML tag used to inflate the MapView
defStyle int: the default style resource ID

Public Methods

public void refresh ()

refresh the web page.

public void setCallbackListener (CallbackListener<UserCredentials> listener)

Registers a CallbackListener on the OAuthView.

Parameters
listener CallbackListener: a CallbackListener

public void setClientId (String clientId)

Sets client Id. Call refresh() afterward to reload the OAuthView.

Parameters
clientId String: the client ID

public void setExpiration (int length)

Sets refresh token expiration time in minutes. Call refresh() afterward to reload the OAuthView. A permanent refresh_token can be requested by specifying expiration=-1

Parameters
length int: expiration time in minutes

public void setOnSslErrorListener (OAuthView.OnSslErrorListener listener)

Registers a OnSslErrorListener on the OAuthView.

Parameters
listener OAuthView.OnSslErrorListener: a OnSslErrorListener

public void setPortalUrl (String url)

Sets portal url. Call refresh() afterward to reload the OAuthView.

Parameters
url String: the url

public void setappID (String appID)

This method is deprecated.
in 10.2.2, use setClientId(String) instead

Sets app ID. Call refresh() afterward to reload the OAuthView.

Parameters
appID String: the app ID