Example usage for android.content Intent createChooser

List of usage examples for android.content Intent createChooser

Introduction

In this page you can find the example usage for android.content Intent createChooser.

Prototype

public static Intent createChooser(Intent target, CharSequence title) 

Source Link

Document

Convenience function for creating a #ACTION_CHOOSER Intent.

Usage

From source file:com.android.mail.compose.ComposeActivity.java

@SuppressLint("NewApi")
private void doAttach(String type) {
    Intent i = new Intent(Intent.ACTION_GET_CONTENT);
    i.addCategory(Intent.CATEGORY_OPENABLE);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    i.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
    i.setType(type);//from  ww w. ja v a 2 s . c om
    mAddingAttachment = true;
    startActivityForResult(Intent.createChooser(i, getText(R.string.select_attachment_type)),
            RESULT_PICK_ATTACHMENT);
}

From source file:org.getlantern.firetweet.util.Utils.java

public static void openMap(final Context context, final double latitude, final double longitude) {
    if (context == null || !ParcelableLocation.isValidLocation(latitude, longitude))
        return;//from  w  ww .j av  a 2 s  . co  m
    final Uri.Builder builder = new Uri.Builder();
    builder.scheme(SCHEME_FIRETWEET);
    builder.authority(AUTHORITY_MAP);
    builder.appendQueryParameter(QUERY_PARAM_LAT, String.valueOf(latitude));
    builder.appendQueryParameter(QUERY_PARAM_LNG, String.valueOf(longitude));
    final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
    intent.setPackage(context.getPackageName());
    context.startActivity(Intent.createChooser(intent, null));
}

From source file:de.vanita5.twittnuker.util.Utils.java

public static void startStatusShareChooser(final Context context, final ParcelableStatus status) {
    final Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    final String name = status.user_name, screenName = status.user_screen_name;
    final String timeString = formatToLongTimeString(context, status.timestamp);
    final String subject = context.getString(R.string.share_subject_format, name, screenName, timeString);
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_TEXT, status.text_plain);
    intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    context.startActivity(Intent.createChooser(intent, context.getString(R.string.share)));
}

From source file:com.bernard.beaconportal.activities.activity.MessageList.java

void onImport() {
    Intent i = new Intent(Intent.ACTION_GET_CONTENT);
    i.addCategory(Intent.CATEGORY_OPENABLE);
    i.setType("*/*");

    PackageManager packageManager = getPackageManager();
    List<ResolveInfo> infos = packageManager.queryIntentActivities(i, 0);

    if (infos.size() > 0) {
        startActivityForResult(Intent.createChooser(i, null), ACTIVITY_REQUEST_PICK_SETTINGS_FILE);
    } else {//from ww  w .  j a  v a 2  s  .  c o m
        showDialog(DIALOG_NO_FILE_MANAGER);
    }
}

From source file:org.getlantern.firetweet.util.Utils.java

public static void startStatusShareChooser(final Context context, final ParcelableStatus status) {
    final Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    final String name = status.user_name, screenName = status.user_screen_name;
    final String timeString = formatToLongTimeString(context, status.timestamp);
    final String subject = context.getString(R.string.status_share_subject_format_with_time, name, screenName,
            timeString);/*  ww  w.ja  v  a 2 s  .c om*/
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_TEXT, status.text_plain);
    intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    context.startActivity(Intent.createChooser(intent, context.getString(R.string.share)));
}

From source file:com.codename1.impl.android.AndroidImplementation.java

/**
 * @inheritDoc/*from  w  w w  .j  ava  2  s .co  m*/
 */
public void sendMessage(String[] recipients, String subject, Message msg) {
    if (editInProgress()) {
        stopEditing(true);
    }
    Intent emailIntent;
    String attachment = msg.getAttachment();
    boolean hasAttachment = (attachment != null && attachment.length() > 0) || msg.getAttachments().size() > 0;

    if (msg.getMimeType().equals(Message.MIME_TEXT) && !hasAttachment) {
        StringBuilder to = new StringBuilder();
        for (int i = 0; i < recipients.length; i++) {
            to.append(recipients[i]);
            to.append(";");
        }
        emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:" + to.toString() + "?subject="
                + Uri.encode(subject) + "&body=" + Uri.encode(msg.getContent())));
    } else {
        if (hasAttachment) {
            if (msg.getAttachments().size() > 1) {
                emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
                emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
                emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
                emailIntent.setType(msg.getMimeType());
                ArrayList<Uri> uris = new ArrayList<Uri>();

                for (String path : msg.getAttachments().keySet()) {
                    uris.add(Uri.parse(fixAttachmentPath(path)));
                }

                emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
            } else {
                emailIntent = new Intent(android.content.Intent.ACTION_SEND);
                emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
                emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
                emailIntent.setType(msg.getMimeType());
                emailIntent.setType(msg.getAttachmentMimeType());
                //if the attachment is in the uder home dir we need to copy it
                //to an accessible dir
                attachment = fixAttachmentPath(attachment);
                emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(attachment));
            }
        } else {
            emailIntent = new Intent(android.content.Intent.ACTION_SEND);
            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
            emailIntent.setType(msg.getMimeType());
        }
        if (msg.getMimeType().equals(Message.MIME_HTML)) {
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(msg.getContent()));
        } else {
            /*
            // Attempted this workaround to fix the ClassCastException that occurs on android when
            // there are multiple attachments.  Unfortunately, this fixes the stack trace, but
            // has the unwanted side-effect of producing a blank message body.
            // Same workaround for HTML mimetype also fails the same way.
            // Conclusion, Just live with the stack trace.  It doesn't seem to affect the
            // execution of the program... treat it as a warning.
            // See https://github.com/codenameone/CodenameOne/issues/1782
            if (msg.getAttachments().size() > 1) {
            ArrayList<String> contentArr = new ArrayList<String>();
            contentArr.add(msg.getContent());
            emailIntent.putStringArrayListExtra(android.content.Intent.EXTRA_TEXT, contentArr);
            } else {
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, msg.getContent());
                    
            }*/
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, msg.getContent());
        }

    }
    final String attach = attachment;
    AndroidNativeUtil.startActivityForResult(Intent.createChooser(emailIntent, "Send mail..."),
            new IntentResultListener() {

                @Override
                public void onActivityResult(int requestCode, int resultCode, Intent data) {
                    if (attach != null && attach.length() > 0 && attach.contains("tmp")) {
                        FileSystemStorage.getInstance().delete(attach);
                    }
                }
            });
}

From source file:com.codename1.impl.android.AndroidImplementation.java

@Override
public void share(String text, String image, String mimeType, Rectangle sourceRect) {
    /*if(!checkForPermission(Manifest.permission.READ_PHONE_STATE, "This is required to perform share")){
    return;//from   www .j a  va  2s.co  m
    }*/
    Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
    if (image == null) {
        shareIntent.setType("text/plain");
        shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, text);
    } else {
        shareIntent.setType(mimeType);
        shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(fixAttachmentPath(image)));
        shareIntent.putExtra(Intent.EXTRA_TEXT, text);
    }
    getContext().startActivity(Intent.createChooser(shareIntent, "Share with..."));
}

From source file:com.android.vending.billing.InAppBillingService.LACK.listAppsFragment.java

public void share_app() {
      if (testSD(true)) {
          DialogInterface.OnClickListener local100 = new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt) {
                  switch (paramAnonymousInt) {
                  default:
                      return;
                  }// www  . j  a  va 2s  . c  o m
                  paramAnonymousDialogInterface = new Thread(new Runnable() {
                      public void run() {
                          Intent localIntent;
                          if (listAppsFragment.pli != null) {
                              localObject = listAppsFragment.this.backup(listAppsFragment.pli);
                              localIntent = new Intent("android.intent.action.SEND");
                              localObject = Uri.parse("file://" + (String) localObject);
                              localIntent.setType("*/*");
                              localIntent.putExtra("android.intent.extra.STREAM", (Parcelable) localObject);
                              if (listAppsFragment.pli != null) {
                                  break label144;
                              }
                          }
                          label144: for (Object localObject = new File(listAppsFragment.rebuldApk)
                                  .getName();; localObject = listAppsFragment.pli.name) {
                              localIntent.setFlags(131072);
                              listAppsFragment.this.startActivity(Intent.createChooser(localIntent,
                                      Utils.getText(2131165795) + " " + (String) localObject));
                              return;
                              localObject = listAppsFragment.rebuldApk;
                              break;
                          }
                      }
                  });
                  paramAnonymousDialogInterface.setPriority(10);
                  paramAnonymousDialogInterface.start();
              }
          };
          Utils.showDialogYesNo(Utils.getText(2131165748), Utils.getText(2131165671), local100, local100, null);
      }
  }