Code example for Activity

Methods: startActivitygetString

0
                               int stringMessage,
                               int stringButtonYes,
                               int stringButtonNo) {
    shareText(activity,
              text,
              activity.getString(stringTitle),
              activity.getString(stringMessage),
              activity.getString(stringButtonYes),
              activity.getString(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. 
   * 
   * @param text the text string to encode as a barcode 
   * @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") 
   */ 
  public static void shareText(Activity activity,
                               CharSequence text,
                               CharSequence stringTitle,
                               CharSequence stringMessage,
                               CharSequence stringButtonYes,
                               CharSequence stringButtonNo) {
 
    Intent intent = new Intent();
    intent.setAction("com.google.zxing.client.android.ENCODE");
    intent.putExtra("ENCODE_TYPE", "TEXT_TYPE");
    intent.putExtra("ENCODE_DATA", text);
    try { 
      activity.startActivity(intent);
    } catch (ActivityNotFoundException e) {
      showDownloadDialog(activity, stringTitle, stringMessage, stringButtonYes, stringButtonNo);
    } 
  }