public final class LevelUpDeepLinkIntegrator extends Object
Deep Link Authorization allows third party apps to request an access token for a LevelUp user
with Intent
s. The intent launches the LevelUp app and the user will be presented with
a dialog describing the request for permissions. Upon choosing to accept or reject the request,
the user will return to the requesting app which will be granted an access token if the request
is accepted.
A request includes a list of permissions, such as the ability to create orders for the user
or to access their transaction history. Permissions
has
definitions for some of
the full list of
available permissions.
To make an authorization request, first hook up the response handler. In your Activity's
onActivityResult()
, call parseActivityResult(int, int, android.content.Intent)
:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// This pulls out your result from the data Intent.
PermissionsRequestResult result =
LevelUpDeepLinkIntegrator.parseActivityResult(requestCode, resultCode, data);
if (result != null) {
if (result.isSuccessful()) {
// Result will contain your access token.
} else {
// The user declined the request or there was as error.
}
} else {
// You can handle your own startActivityForResult results here.
}
}
When you are ready to request permissions, create an instance of LevelUpDeepLinkIntegrator
from your Activity and call requestPermissions(java.util.Collection<java.lang.String>)
with a list
of desired permissions:
if (LevelUpDeepLinkIntegrator.isLevelUpInstalled()) {
LevelUpDeepLinkIntegrator integrator =
new LevelUpDeepLinkIntegrator(yourActivity, yourAppId);
integrator.requestPermissions(DeepLinkAuthUtil.Permissions.PERMISSION_CREATE_ORDERS);
} else {
// If you get here, LevelUp isn't installed or the installed version doesn't support
// deep link auth. This might be a good place to suggest someone download LevelUp!
}
Modifier and Type | Class and Description |
---|---|
static class |
LevelUpDeepLinkIntegrator.PermissionsRequestResult
The result of a call to
requestPermissions(java.util.Collection<java.lang.String>) . |
Constructor and Description |
---|
LevelUpDeepLinkIntegrator(Activity activity,
int appId)
This can be instantiated in
Activity.onCreate(android.os.Bundle) . |
Modifier and Type | Method and Description |
---|---|
protected AlertDialog |
getInstallDialog(Activity activity)
Constructs an
AlertDialog which prompts the user to download LevelUp. |
protected Uri |
getPlayLink(Context context,
String packageName)
Retrieves the Google Play link for the given package name.
|
static boolean |
isLevelUpAvailable(Context context) |
protected AlertDialog |
onLevelUpNotInstalled(Activity activity)
Called when LevelUp is not installed.
|
protected void |
onNegativeButton(DialogInterface dialog)
Called when the negative action button (Cancel) is pressed on the install dialog.
|
protected void |
onPositiveButton(DialogInterface dialog)
Called when the positive action button (install LevelUp) is pressed in the install dialog.
|
static LevelUpDeepLinkIntegrator.PermissionsRequestResult |
parseActivityResult(int requestCode,
int resultCode,
Intent data)
Call this from
Activity.onActivityResult(int, int, android.content.Intent) . |
AlertDialog |
requestPermissions(Collection<String> permissionKeys)
Send a request to the LevelUp app to prompt the user to grant your app the requested
permissions.
|
AlertDialog |
requestPermissions(String... permissionKeys)
Send a request to the LevelUp app to prompt the user to grant your app the requested
permissions.
|
void |
setInstallDialogMessage(CharSequence message)
Sets the message that's displayed when the LevelUp app isn't installed on the device.
|
void |
setInstallDialogTitle(CharSequence title)
Sets the title of the dialog box that's displayed when the LevelUp app isn't installed on the device.
|
public LevelUpDeepLinkIntegrator(Activity activity, int appId)
Activity.onCreate(android.os.Bundle)
. This class keeps a weak
reference to your activity, so you don't need to worry about it being leaked.activity
- your activity.appId
- your app's web service ID.public static boolean isLevelUpAvailable(Context context)
context
- application context.public static LevelUpDeepLinkIntegrator.PermissionsRequestResult parseActivityResult(int requestCode, int resultCode, Intent data)
Activity.onActivityResult(int, int, android.content.Intent)
.requestCode
- the requestCode from onActivityResultresultCode
- the resultCode from onActivityResultdata
- the data from onActivityResultpublic final AlertDialog requestPermissions(Collection<String> permissionKeys)
parseActivityResult(int, int, android.content.Intent)
from Activity.onActivityResult(int, int, android.content.Intent)
in order to get the response from LevelUp.permissionKeys
- the set of permissions that you wish to request. See Permissions
.public final AlertDialog requestPermissions(String... permissionKeys)
parseActivityResult(int, int, android.content.Intent)
from Activity.onActivityResult(int, int, android.content.Intent)
in order to get the response from LevelUp.permissionKeys
- the set of permissions that you wish to request. See Permissions
.public final void setInstallDialogMessage(CharSequence message)
message
- the body text.R.string.levelup_deep_link_auth_install_message
public final void setInstallDialogTitle(CharSequence title)
title
- the dialog box's title.R.string.levelup_deep_link_auth_install_title
protected AlertDialog getInstallDialog(Activity activity)
AlertDialog
which prompts the user to download LevelUp. Alternative
text can be set using setInstallDialogMessage(java.lang.CharSequence)
and setInstallDialogTitle(java.lang.CharSequence)
or
by overlaying the associated strings resources.activity
- the activity that is responsible for the dialog (your activity).protected Uri getPlayLink(Context context, String packageName)
context
- application context.packageName
- the package to display.protected AlertDialog onLevelUpNotInstalled(Activity activity)
activity
- AlertDialog
that was shown to the user.protected void onNegativeButton(DialogInterface dialog)
dialog
- protected void onPositiveButton(DialogInterface dialog)
dialog
-