|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.zxing.integration.android.IntentIntegrator
public final class IntentIntegrator
A utility class which helps ease integration with Barcode Scanner via Intent
s. This is a simple
way to invoke barcode scanning and receive the result, without any need to integrate, modify, or learn the
project's source code.
Integration is essentially as easy as calling initiateScan(Activity)
and waiting
for the result in your app.
It does require that the Barcode Scanner application is installed. The
initiateScan(Activity)
method will prompt the user to download the application, if needed.
There are a few steps to using this integration. First, your Activity
must implement
the method Activity.onActivityResult(int, int, Intent)
and include a line of code like this:
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanResult != null) {
// handle scan result
}
// else continue with any other code you need in the method
...
}
This is where you will handle a scan result. Second, just call this in response to a user action somewhere to begin the scan process:
IntentIntegrator.initiateScan(yourActivity);
You can use initiateScan(Activity, CharSequence, CharSequence, CharSequence, CharSequence)
or
initiateScan(Activity, int, int, int, int)
to customize the download prompt with
different text labels.
Note that initiateScan(Activity)
returns an AlertDialog
which is non-null if the
user was prompted to download the application. This lets the calling app potentially manage the dialog.
In particular, ideally, the app dismisses the dialog if it's still active in its Activity.onPause()
method.
To share text, encoded as a QR Code on-screen, similarly, see shareText(Activity, CharSequence)
.
Some code, particularly download integration, was contributed from the Anobiit application.
Field Summary | |
---|---|
static java.lang.String |
ALL_CODE_TYPES
|
static java.lang.String |
DEFAULT_MESSAGE
|
static java.lang.String |
DEFAULT_NO
|
static java.lang.String |
DEFAULT_TITLE
|
static java.lang.String |
DEFAULT_YES
|
static java.lang.String |
ONE_D_CODE_TYPES
|
static java.lang.reflect.Method |
PACKAGE_SETTER
|
static java.lang.String |
PRODUCT_CODE_TYPES
|
static java.lang.String |
QR_CODE_TYPES
|
static int |
REQUEST_CODE
|
Method Summary | |
---|---|
static android.app.AlertDialog |
initiateScan(android.app.Activity activity)
See initiateScan(Activity, CharSequence, CharSequence, CharSequence, CharSequence) --
same, but uses default English labels. |
static android.app.AlertDialog |
initiateScan(android.app.Activity activity,
java.lang.CharSequence stringTitle,
java.lang.CharSequence stringMessage,
java.lang.CharSequence stringButtonYes,
java.lang.CharSequence stringButtonNo)
See initiateScan(Activity, CharSequence, CharSequence, CharSequence, CharSequence, CharSequence) --
same, but scans for all supported barcode types. |
static android.app.AlertDialog |
initiateScan(android.app.Activity activity,
java.lang.CharSequence stringTitle,
java.lang.CharSequence stringMessage,
java.lang.CharSequence stringButtonYes,
java.lang.CharSequence stringButtonNo,
java.lang.CharSequence stringDesiredBarcodeFormats)
Invokes scanning. |
static android.app.AlertDialog |
initiateScan(android.app.Activity activity,
int stringTitle,
int stringMessage,
int stringButtonYes,
int stringButtonNo)
See initiateScan(Activity, CharSequence, CharSequence, CharSequence, CharSequence) --
same, but takes string IDs which refer
to the Activity 's resource bundle entries. |
static IntentResult |
parseActivityResult(int requestCode,
int resultCode,
android.content.Intent intent)
Call this from your Activity 's
Activity.onActivityResult(int, int, Intent) method. |
static void |
shareText(android.app.Activity activity,
java.lang.CharSequence text)
See shareText(Activity, CharSequence, CharSequence, CharSequence, CharSequence, CharSequence) --
same, but uses default English labels. |
static void |
shareText(android.app.Activity activity,
java.lang.CharSequence text,
java.lang.CharSequence stringTitle,
java.lang.CharSequence stringMessage,
java.lang.CharSequence stringButtonYes,
java.lang.CharSequence stringButtonNo)
Shares the given text by encoding it as a barcode, such that another user can scan the text off the screen of the device. |
static void |
shareText(android.app.Activity activity,
java.lang.CharSequence text,
int stringTitle,
int stringMessage,
int stringButtonYes,
int stringButtonNo)
See shareText(Activity, CharSequence, CharSequence, CharSequence, CharSequence, CharSequence) --
same, but takes string IDs which refer to the Activity 's resource bundle entries. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int REQUEST_CODE
public static final java.lang.String DEFAULT_TITLE
public static final java.lang.String DEFAULT_MESSAGE
public static final java.lang.String DEFAULT_YES
public static final java.lang.String DEFAULT_NO
public static final java.lang.String PRODUCT_CODE_TYPES
public static final java.lang.String ONE_D_CODE_TYPES
public static final java.lang.String QR_CODE_TYPES
public static final java.lang.String ALL_CODE_TYPES
public static final java.lang.reflect.Method PACKAGE_SETTER
Method Detail |
---|
public static android.app.AlertDialog initiateScan(android.app.Activity activity)
initiateScan(Activity, CharSequence, CharSequence, CharSequence, CharSequence)
--
same, but uses default English labels.
public static android.app.AlertDialog initiateScan(android.app.Activity activity, int stringTitle, int stringMessage, int stringButtonYes, int stringButtonNo)
initiateScan(Activity, CharSequence, CharSequence, CharSequence, CharSequence)
--
same, but takes string IDs which refer
to the Activity
's resource bundle entries.
public static android.app.AlertDialog initiateScan(android.app.Activity activity, java.lang.CharSequence stringTitle, java.lang.CharSequence stringMessage, java.lang.CharSequence stringButtonYes, java.lang.CharSequence stringButtonNo)
initiateScan(Activity, CharSequence, CharSequence, CharSequence, CharSequence, CharSequence)
--
same, but scans for all supported barcode types.
stringTitle
- title of dialog prompting user to download Barcode ScannerstringMessage
- text of dialog prompting user to download Barcode ScannerstringButtonYes
- text of button user clicks when agreeing to download
Barcode Scanner (e.g. "Yes")stringButtonNo
- text of button user clicks when declining to download
Barcode Scanner (e.g. "No")
AlertDialog
if the user was prompted to download the app,
null otherwisepublic static android.app.AlertDialog initiateScan(android.app.Activity activity, java.lang.CharSequence stringTitle, java.lang.CharSequence stringMessage, java.lang.CharSequence stringButtonYes, java.lang.CharSequence stringButtonNo, java.lang.CharSequence stringDesiredBarcodeFormats)
stringTitle
- title of dialog prompting user to download Barcode ScannerstringMessage
- text of dialog prompting user to download Barcode ScannerstringButtonYes
- text of button user clicks when agreeing to download
Barcode Scanner (e.g. "Yes")stringButtonNo
- text of button user clicks when declining to download
Barcode Scanner (e.g. "No")stringDesiredBarcodeFormats
- a comma separated list of codes you would
like to scan for.
AlertDialog
if the user was prompted to download the app,
null otherwise
java.lang.InterruptedException
- if timeout expires before a scan completespublic static IntentResult parseActivityResult(int requestCode, int resultCode, android.content.Intent intent)
Call this from your Activity
's
Activity.onActivityResult(int, int, Intent)
method.
IntentResult
containing the result of the scan. If the user cancelled scanning,
the fields will be null.public static void shareText(android.app.Activity activity, java.lang.CharSequence text)
shareText(Activity, CharSequence, CharSequence, CharSequence, CharSequence, CharSequence)
--
same, but uses default English labels.
public static void shareText(android.app.Activity activity, java.lang.CharSequence text, int stringTitle, int stringMessage, int stringButtonYes, int stringButtonNo)
shareText(Activity, CharSequence, CharSequence, CharSequence, CharSequence, CharSequence)
--
same, but takes string IDs which refer to the Activity
's resource bundle entries.
public static void shareText(android.app.Activity activity, java.lang.CharSequence text, java.lang.CharSequence stringTitle, java.lang.CharSequence stringMessage, java.lang.CharSequence stringButtonYes, java.lang.CharSequence stringButtonNo)
text
- the text string to encode as a barcodestringTitle
- title of dialog prompting user to download Barcode ScannerstringMessage
- text of dialog prompting user to download Barcode ScannerstringButtonYes
- text of button user clicks when agreeing to download
Barcode Scanner (e.g. "Yes")stringButtonNo
- text of button user clicks when declining to download
Barcode Scanner (e.g. "No")
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |