docs/apidocs/com/google/zxing/integration/android/IntentIntegrator.html
com.google.zxing.integration.android
public classIntentIntegratorextends[Object](https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true "class or interface in java.lang")
A utility class which helps ease integration with Barcode Scanner via Intents. 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.
To integrate, create an instance of IntentIntegrator and call initiateScan() and wait for the result in your app.
It does require that the Barcode Scanner (or work-alike) application is installed. The initiateScan() 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 integrator = new IntentIntegrator(yourActivity);
integrator.initiateScan();
Note that initiateScan() 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.
You can use setTitle(String) to customize the title of this download prompt dialog (or, use setTitleByID(int) to set the title by string resource ID.) Likewise, the prompt message, and yes/no button labels can be changed.
Finally, you can use addExtra(String, Object) to add more parameters to the Intent used to invoke the scanner. This can be used to set additional options not directly exposed by this simplified API.
By default, this will only allow applications that are known to respond to this intent correctly do so. The apps that are allowed to response can be set with setTargetApplications(List). For example, set to TARGET_BARCODE_SCANNER_ONLY to only target the Barcode Scanner app itself.
To share text, encoded as a QR Code on-screen, similarly, see shareText(CharSequence).
Some code, particularly download integration, was contributed from the Anobiit application.
Some formats are not enabled by default even when scanning with ALL_CODE_TYPES, such as PDF417. Use initiateScan(Collection) with a collection containing the names of formats to scan for explicitly, like "PDF_417", to use such formats.
Author:Sean Owen, Fred Lin, Isaac Potoczny-Jones, Brad Drehmer, gcstang
Fields | Modifier and Type | Field and Description |
| --- | --- |
| static Collection<String> | ALL_CODE_TYPES |
| static Collection<String> | DATA_MATRIX_TYPES |
| static String | DEFAULT_MESSAGE |
| static String | DEFAULT_NO |
| static String | DEFAULT_TITLE |
| static String | DEFAULT_YES |
| static Collection<String> | ONE_D_CODE_TYPES |
| static Collection<String> | PRODUCT_CODE_TYPES |
| static Collection<String> | QR_CODE_TYPES |
| static int | REQUEST_CODE |
| static List<String> | TARGET_ALL_KNOWN |
| static List<String> | TARGET_BARCODE_SCANNER_ONLY |
Constructors | Constructor and Description |
| --- |
| IntentIntegrator(android.app.Activity activity) |
| IntentIntegrator(android.app.Fragment fragment) |
All Methods Static Methods Instance Methods Concrete Methods | Modifier and Type | Method and Description |
| --- | --- |
| void | addExtra(String key, Object value) |
| String | getButtonNo() |
| String | getButtonYes() |
| String | getMessage() |
| Map<String,?> | getMoreExtras() |
| Collection<String> | getTargetApplications() |
| String | getTitle() |
| android.app.AlertDialog | initiateScan()
Initiates a scan for all known barcode types with the default camera.
|
| android.app.AlertDialog | initiateScan(Collection<String> desiredBarcodeFormats)
Initiates a scan, using the default camera, only for a certain set of barcode types, given as strings corresponding to their names in ZXing's BarcodeFormat class like "UPC_A".
|
| android.app.AlertDialog | initiateScan(Collection<String> desiredBarcodeFormats, int cameraId)
Initiates a scan, using the specified camera, only for a certain set of barcode types, given as strings corresponding to their names in ZXing's BarcodeFormat class like "UPC_A".
|
| android.app.AlertDialog | initiateScan(int cameraId)
Initiates a scan for all known barcode types with the specified camera.
|
| static IntentResult | parseActivityResult(int requestCode, int resultCode, android.content.Intent intent)
Call this from your Activity's Activity.onActivityResult(int, int, Intent) method.
|
| void | setButtonNo(String buttonNo) |
| void | setButtonNoByID(int buttonNoID) |
| void | setButtonYes(String buttonYes) |
| void | setButtonYesByID(int buttonYesID) |
| void | setMessage(String message) |
| void | setMessageByID(int messageID) |
| void | setSingleTargetApplication(String targetApplication) |
| void | setTargetApplications(List<String> targetApplications) |
| void | setTitle(String title) |
| void | setTitleByID(int titleID) |
| android.app.AlertDialog | shareText(CharSequence text)
Defaults to type "TEXT_TYPE".
|
| android.app.AlertDialog | shareText(CharSequence text, CharSequence type)
Shares the given text by encoding it as a barcode, such that another user can scan the text off the screen of the device.
|
| protected void | startActivityForResult(android.content.Intent intent, int code)
Start an activity.
|
-
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
public static final int REQUEST_CODE
See Also:Constant Field Values
-
public static final[String](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true "class or interface in java.lang")DEFAULT_TITLE
See Also:Constant Field Values
-
public static final[String](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true "class or interface in java.lang")DEFAULT_MESSAGE
See Also:Constant Field Values
-
public static final[String](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true "class or interface in java.lang")DEFAULT_YES
See Also:Constant Field Values
-
public static final[String](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true "class or interface in java.lang")DEFAULT_NO
See Also:Constant Field Values
-
public static final[Collection](https://docs.oracle.com/javase/7/docs/api/java/util/Collection.html?is-external=true "class or interface in java.util")<[String](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true "class or interface in java.lang")> PRODUCT_CODE_TYPES
-
public static final[Collection](https://docs.oracle.com/javase/7/docs/api/java/util/Collection.html?is-external=true "class or interface in java.util")<[String](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true "class or interface in java.lang")> ONE_D_CODE_TYPES
-
public static final[Collection](https://docs.oracle.com/javase/7/docs/api/java/util/Collection.html?is-external=true "class or interface in java.util")<[String](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true "class or interface in java.lang")> QR_CODE_TYPES
-
public static final[Collection](https://docs.oracle.com/javase/7/docs/api/java/util/Collection.html?is-external=true "class or interface in java.util")<[String](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true "class or interface in java.lang")> DATA_MATRIX_TYPES
-
public static final[Collection](https://docs.oracle.com/javase/7/docs/api/java/util/Collection.html?is-external=true "class or interface in java.util")<[String](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true "class or interface in java.lang")> ALL_CODE_TYPES
-
public static final[List](https://docs.oracle.com/javase/7/docs/api/java/util/List.html?is-external=true "class or interface in java.util")<[String](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true "class or interface in java.lang")> TARGET_BARCODE_SCANNER_ONLY
-
public static final[List](https://docs.oracle.com/javase/7/docs/api/java/util/List.html?is-external=true "class or interface in java.util")<[String](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true "class or interface in java.lang")> TARGET_ALL_KNOWN
-
public IntentIntegrator(android.app.Activity activity)
Parameters:activity - Activity invoking the integration
-
public IntentIntegrator(android.app.Fragment fragment)
Parameters:fragment - Fragment invoking the integration. startActivityForResult(Intent, int) will be called on the Fragment instead of an Activity
-
public[String](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true "class or interface in java.lang")getTitle()
-
public void setTitle([String](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true "class or interface in java.lang")title)
-
public void setTitleByID(int titleID)
-
public[String](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true "class or interface in java.lang")getMessage()
-
public void setMessage([String](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true "class or interface in java.lang")message)
-
public void setMessageByID(int messageID)
-
public[String](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true "class or interface in java.lang")getButtonYes()
-
public void setButtonYes([String](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true "class or interface in java.lang")buttonYes)
-
public void setButtonYesByID(int buttonYesID)
-
public[String](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true "class or interface in java.lang")getButtonNo()
-
public void setButtonNo([String](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true "class or interface in java.lang")buttonNo)
-
public void setButtonNoByID(int buttonNoID)
-
public[Collection](https://docs.oracle.com/javase/7/docs/api/java/util/Collection.html?is-external=true "class or interface in java.util")<[String](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true "class or interface in java.lang")> getTargetApplications()
-
public final void setTargetApplications([List](https://docs.oracle.com/javase/7/docs/api/java/util/List.html?is-external=true "class or interface in java.util")<[String](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true "class or interface in java.lang")> targetApplications)
-
public void setSingleTargetApplication([String](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true "class or interface in java.lang")targetApplication)
-
public[Map](https://docs.oracle.com/javase/7/docs/api/java/util/Map.html?is-external=true "class or interface in java.util")<[String](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true "class or interface in java.lang"),?> getMoreExtras()
-
public final void addExtra([String](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true "class or interface in java.lang")key,[Object](https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true "class or interface in java.lang")value)
-
public final android.app.AlertDialog initiateScan()
Initiates a scan for all known barcode types with the default camera.
Returns:the AlertDialog that was shown to the user prompting them to download the app if a prompt was needed, or null otherwise.
-
public final android.app.AlertDialog initiateScan(int cameraId)
Initiates a scan for all known barcode types with the specified camera.
Parameters:cameraId - camera ID of the camera to use. A negative value means "no preference".Returns:the AlertDialog that was shown to the user prompting them to download the app if a prompt was needed, or null otherwise.
-
public final android.app.AlertDialog initiateScan([Collection](https://docs.oracle.com/javase/7/docs/api/java/util/Collection.html?is-external=true "class or interface in java.util")<[String](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true "class or interface in java.lang")> desiredBarcodeFormats)
Initiates a scan, using the default camera, only for a certain set of barcode types, given as strings corresponding to their names in ZXing's BarcodeFormat class like "UPC_A". You can supply constants like PRODUCT_CODE_TYPES for example.
Parameters:desiredBarcodeFormats - names of BarcodeFormats to scan forReturns:the AlertDialog that was shown to the user prompting them to download the app if a prompt was needed, or null otherwise.
-
public final android.app.AlertDialog initiateScan([Collection](https://docs.oracle.com/javase/7/docs/api/java/util/Collection.html?is-external=true "class or interface in java.util")<[String](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true "class or interface in java.lang")> desiredBarcodeFormats,
int cameraId)
Initiates a scan, using the specified camera, only for a certain set of barcode types, given as strings corresponding to their names in ZXing's BarcodeFormat class like "UPC_A". You can supply constants like PRODUCT_CODE_TYPES for example.
Parameters:desiredBarcodeFormats - names of BarcodeFormats to scan forcameraId - camera ID of the camera to use. A negative value means "no preference".Returns:the AlertDialog that was shown to the user prompting them to download the app if a prompt was needed, or null otherwise
-
protected void startActivityForResult(android.content.Intent intent,
int code)
Start an activity. This method is defined to allow different methods of activity starting for newer versions of Android and for compatibility library.
Parameters:intent - Intent to start.code - Request code for the activitySee Also:Activity.startActivityForResult(Intent, int), Fragment.startActivityForResult(Intent, int)
-
public static[IntentResult](../../../../../com/google/zxing/integration/android/IntentResult.html "class in com.google.zxing.integration.android")parseActivityResult(int requestCode,
int resultCode,
android.content.Intent intent)
Call this from your Activity's Activity.onActivityResult(int, int, Intent) method.
Parameters:requestCode - request code from onActivityResult()``resultCode - result code from onActivityResult()``intent - Intent from onActivityResult()Returns:null if the event handled here was not related to this class, or else an IntentResult containing the result of the scan. If the user cancelled scanning, the fields will be null.
-
public final android.app.AlertDialog shareText([CharSequence](https://docs.oracle.com/javase/7/docs/api/java/lang/CharSequence.html?is-external=true "class or interface in java.lang")text)
Defaults to type "TEXT_TYPE".
Parameters:text - the text string to encode as a barcodeReturns:the AlertDialog that was shown to the user prompting them to download the app if a prompt was needed, or null otherwiseSee Also:shareText(CharSequence, CharSequence)
-
public final android.app.AlertDialog shareText([CharSequence](https://docs.oracle.com/javase/7/docs/api/java/lang/CharSequence.html?is-external=true "class or interface in java.lang")text,[CharSequence](https://docs.oracle.com/javase/7/docs/api/java/lang/CharSequence.html?is-external=true "class or interface in java.lang")type)
Shares the given text by encoding it as a barcode, such that another user can scan the text off the screen of the device.
Parameters:text - the text string to encode as a barcodetype - type of data to encode. See com.google.zxing.client.android.Contents.Type constants.Returns:the AlertDialog that was shown to the user prompting them to download the app if a prompt was needed, or null otherwise
Copyright © 2007–2018. All rights reserved.