Code example for Activity

Methods: startActivityForResultgetString

0
                                         int stringTitle,
                                         int stringMessage,
                                         int stringButtonYes,
                                         int stringButtonNo) {
    return initiateScan(activity,
                        activity.getString(stringTitle),
                        activity.getString(stringMessage),
                        activity.getString(stringButtonYes),
                        activity.getString(stringButtonNo));
  } 
 
  /** 
   * See {@link #initiateScan(Activity, CharSequence, CharSequence, CharSequence, CharSequence, CharSequence)} -- 
   * same, but scans for all supported barcode types. 
   * @param stringTitle title of dialog prompting user to download Barcode Scanner 
   * @param stringMessage text of dialog prompting user to download Barcode Scanner 
   * @param stringButtonYes text of button user clicks when agreeing to download 
   *  Barcode Scanner (e.g. "Yes") 
   * @param stringButtonNo text of button user clicks when declining to download 
   *  Barcode Scanner (e.g. "No") 
   * @return an {@link AlertDialog} if the user was prompted to download the app, 
   *  null otherwise 
   */ 
  public static AlertDialog initiateScan(Activity activity,
                                         CharSequence stringTitle,
                                         CharSequence stringMessage,
                                         CharSequence stringButtonYes,
                                         CharSequence stringButtonNo) {
 
    return initiateScan(activity,
                        stringTitle,
                        stringMessage,
                        stringButtonYes,
                        stringButtonNo,
                        ALL_CODE_TYPES);
  } 
 
  /** 
   * Invokes scanning. 
   * 
   * @param stringTitle title of dialog prompting user to download Barcode Scanner 
   * @param stringMessage text of dialog prompting user to download Barcode Scanner 
   * @param stringButtonYes text of button user clicks when agreeing to download 
   *  Barcode Scanner (e.g. "Yes") 
   * @param stringButtonNo text of button user clicks when declining to download 
   *  Barcode Scanner (e.g. "No") 
   * @param stringDesiredBarcodeFormats a comma separated list of codes you would 
   *  like to scan for. 
   * @return an {@link AlertDialog} if the user was prompted to download the app, 
   *  null otherwise 
   * @throws InterruptedException if timeout expires before a scan completes 
   */ 
  public static AlertDialog initiateScan(Activity activity,
                                         CharSequence stringTitle,
                                         CharSequence stringMessage,
                                         CharSequence stringButtonYes,
                                         CharSequence stringButtonNo,
                                         CharSequence stringDesiredBarcodeFormats) {
    Intent intentScan = new Intent("com.google.zxing.client.android.SCAN");
    intentScan.addCategory(Intent.CATEGORY_DEFAULT);
 
    // check which types of codes to scan for 
    if (stringDesiredBarcodeFormats != null) {
      // set the desired barcode types 
      intentScan.putExtra("SCAN_FORMATS", stringDesiredBarcodeFormats);
    } 
 
    try { 
      activity.startActivityForResult(intentScan, REQUEST_CODE);
      return null; 
    } catch (ActivityNotFoundException e) {
      return showDownloadDialog(activity, stringTitle, stringMessage, stringButtonYes, stringButtonNo);
    } 
  } 
Experience pair programming with AI  Get Codota for Java