Пример #1
0
 public void shareText(String type, Bundle data) {
   Intent intent = new Intent();
   intent.addCategory(Intent.CATEGORY_DEFAULT);
   intent.setAction(BS_PACKAGE + ".ENCODE");
   intent.putExtra("ENCODE_TYPE", type);
   intent.putExtra("ENCODE_DATA", data);
   String targetAppPackage = findTargetAppPackage(intent);
   if (targetAppPackage == null) {
     showDownloadDialog();
   } else {
     intent.setPackage(targetAppPackage);
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
     activity.startActivity(intent);
   }
 }
 /**
  * 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(PACKAGE + ".ENCODE");
   setPackage(intent);
   intent.putExtra("ENCODE_TYPE", "TEXT_TYPE");
   intent.putExtra("ENCODE_DATA", text);
   try {
     activity.startActivity(intent);
   } catch (ActivityNotFoundException e) {
     showDownloadDialog(activity, stringTitle, stringMessage, stringButtonYes, stringButtonNo);
   }
 }