Skip to content

Latest commit

 

History

History
106 lines (89 loc) · 3.65 KB

active-directory-develop-guidedsetup-android-setup.md

File metadata and controls

106 lines (89 loc) · 3.65 KB
title description services documentationcenter author manager editor ms.assetid ms.service ms.devlang ms.topic ms.tgt_pltfrm ms.workload ms.date ms.author ms.custom
include file
include file
active-directory
dev-center-name
andretms
mtillman
820acdb7-d316-4c3b-8de9-79df48ba3b06
active-directory
na
include
na
identity
09/13/2018
andret
include file

Set up your project

Do you want to download this sample's Android Studio project instead? Download a project, and skip to the Configuration step to configure the code sample before you execute it.

Create a new project

  1. Open Android Studio, and then select File > New > New Project.
  2. Name your application, and then select Next.
  3. Select API 21 or newer (Android 5.0), and then select Next.
  4. Leave Empty Activity as it is, select Next, and then select Finish.

Add MSAL to your project

  1. In Android Studio, select Gradle Scripts > build.gradle (Module: app).

  2. Under Dependencies, paste the following code:

    compile ('com.microsoft.identity.client:msal:0.1.+') {
        exclude group: 'com.android.support', module: 'appcompat-v7'
    }
    compile 'com.android.volley:volley:1.0.0'

About this package

The package in the preceding code installs Microsoft Authentication Library. MSAL handles all token operations including acquiring, caching, refreshing, and deleting. The tokens are needed to access the APIs protected by Microsoft's identity platform.

Create the app's UI

  1. Go to res > layout, and then open activity_main.xml.

  2. Change the activity layout from android.support.constraint.ConstraintLayout or other to LinearLayout.

  3. Add the android:orientation="vertical" property to the LinearLayout node.

  4. Paste the following code into the LinearLayout node, replacing the current content:

    <TextView
        android:text="Welcome, "
        android:textColor="#3f3f3f"
        android:textSize="50px"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="15dp"
        android:id="@+id/welcome"
        android:visibility="invisible"/>
    
    <Button
        android:id="@+id/callGraph"
        android:text="Call Microsoft Graph"
        android:textColor="#FFFFFF"
        android:background="#00a1f1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="200dp"
        android:textAllCaps="false" />
    
    <TextView
        android:text="Getting Graph Data..."
        android:textColor="#3f3f3f"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:id="@+id/graphData"
        android:visibility="invisible"/>
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:gravity="center|bottom"
        android:orientation="vertical" >
    
        <Button
            android:text="Sign Out"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="15dp"
            android:textColor="#FFFFFF"
            android:background="#00a1f1"
            android:textAllCaps="false"
            android:id="@+id/clearCache"
            android:visibility="invisible" />
    </LinearLayout>