|
||||||||||
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 String |
ALL_CODE_TYPES
The Constant ALL_CODE_TYPES. |
static String |
DEFAULT_MESSAGE
The Constant DEFAULT_MESSAGE. |
static String |
DEFAULT_NO
The Constant DEFAULT_NO. |
static String |
DEFAULT_TITLE
The Constant DEFAULT_TITLE. |
static String |
DEFAULT_YES
The Constant DEFAULT_YES. |
static String |
ONE_D_CODE_TYPES
The Constant ONE_D_CODE_TYPES. |
static String |
PRODUCT_CODE_TYPES
The Constant PRODUCT_CODE_TYPES. |
static String |
QR_CODE_TYPES
The Constant QR_CODE_TYPES. |
static int |
REQUEST_CODE
The Constant REQUEST_CODE. |
Method Summary | |
---|---|
static AlertDialog |
initiateScan(Activity activity)
See. |
static AlertDialog |
initiateScan(Activity activity,
CharSequence stringTitle,
CharSequence stringMessage,
CharSequence stringButtonYes,
CharSequence stringButtonNo)
See. |
static AlertDialog |
initiateScan(Activity activity,
CharSequence stringTitle,
CharSequence stringMessage,
CharSequence stringButtonYes,
CharSequence stringButtonNo,
CharSequence stringDesiredBarcodeFormats)
Invokes scanning. |
static AlertDialog |
initiateScan(Activity activity,
int stringTitle,
int stringMessage,
int stringButtonYes,
int stringButtonNo)
See. |
static IntentResult |
parseActivityResult(int requestCode,
int resultCode,
Intent intent)
Call this from your Activity 's. |
static void |
shareText(Activity activity,
CharSequence text)
See. |
static void |
shareText(Activity activity,
CharSequence text,
CharSequence stringTitle,
CharSequence stringMessage,
CharSequence stringButtonYes,
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(Activity activity,
CharSequence text,
int stringTitle,
int stringMessage,
int stringButtonYes,
int stringButtonNo)
See. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int REQUEST_CODE
public static final String DEFAULT_TITLE
public static final String DEFAULT_MESSAGE
public static final String DEFAULT_YES
public static final String DEFAULT_NO
public static final String PRODUCT_CODE_TYPES
public static final String ONE_D_CODE_TYPES
public static final String QR_CODE_TYPES
public static final String ALL_CODE_TYPES
Method Detail |
---|
public static AlertDialog initiateScan(Activity activity)
activity
- the activity
initiateScan(Activity, CharSequence, CharSequence, CharSequence,
CharSequence)
-- same, but uses default English labels.public static AlertDialog initiateScan(Activity activity, int stringTitle, int stringMessage, int stringButtonYes, int stringButtonNo)
activity
- the activitystringTitle
- the string titlestringMessage
- the string messagestringButtonYes
- the string button yesstringButtonNo
- the string button no
initiateScan(Activity, CharSequence, CharSequence, CharSequence,
CharSequence)
-- same, but takes string IDs which refer to the Activity
's resource bundle entries.public static AlertDialog initiateScan(Activity activity, CharSequence stringTitle, CharSequence stringMessage, CharSequence stringButtonYes, CharSequence stringButtonNo)
activity
- the activitystringTitle
- 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 otherwise
initiateScan(Activity, CharSequence, CharSequence, CharSequence,
CharSequence, CharSequence)
-- same, but scans for all supported barcode types.public static AlertDialog initiateScan(Activity activity, CharSequence stringTitle, CharSequence stringMessage, CharSequence stringButtonYes, CharSequence stringButtonNo, CharSequence stringDesiredBarcodeFormats)
activity
- the activitystringTitle
- 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 otherwisepublic static IntentResult parseActivityResult(int requestCode, int resultCode, Intent intent)
Call this from your Activity
's.
requestCode
- the request coderesultCode
- the result codeintent
- the intent
IntentResult
containing the result of the scan.
If the user cancelled scanning, the fields will be null.
Activity.onActivityResult(int, int, Intent)
method.
public static void shareText(Activity activity, CharSequence text)
activity
- the activitytext
- the text
shareText(Activity, CharSequence, CharSequence, CharSequence,
CharSequence, CharSequence)
-- same, but uses default English labels.public static void shareText(Activity activity, CharSequence text, int stringTitle, int stringMessage, int stringButtonYes, int stringButtonNo)
activity
- the activitytext
- the textstringTitle
- the string titlestringMessage
- the string messagestringButtonYes
- the string button yesstringButtonNo
- the string button no
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(Activity activity, CharSequence text, CharSequence stringTitle, CharSequence stringMessage, CharSequence stringButtonYes, CharSequence stringButtonNo)
activity
- the activitytext
- 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 |