Example usage for android.content Intent EXTRA_INITIAL_INTENTS

List of usage examples for android.content Intent EXTRA_INITIAL_INTENTS

Introduction

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

Prototype

String EXTRA_INITIAL_INTENTS

To view the source code for android.content Intent EXTRA_INITIAL_INTENTS.

Click Source Link

Document

A Parcelable[] of Intent or android.content.pm.LabeledIntent objects as set with #putExtra(String,Parcelable[]) of additional activities to place a the front of the list of choices, when shown to the user with a #ACTION_CHOOSER .

Usage

From source file:com.core.base.js.UploadHandler.java

private Intent createChooserIntent(Intent... intents) {
    Intent chooser = new Intent(Intent.ACTION_CHOOSER);
    chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, intents);
    chooser.putExtra(Intent.EXTRA_TITLE, "Choose file for upload");
    return chooser;
}

From source file:com.scoreflex.ScoreflexView.java

/**
 * The constructor of the view.//from  ww  w  .j av  a2  s  .  co m
 * @param activity The activity holding the view.
 * @param attrs
 * @param defStyle
 */
@SuppressWarnings("deprecation")
public ScoreflexView(Activity activity, AttributeSet attrs, int defStyle) {
    super(activity, attrs, defStyle);

    // Keep a reference on the activity
    mParentActivity = activity;

    // Default layout params
    if (null == getLayoutParams()) {
        setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                Scoreflex.getDensityIndependantPixel(R.dimen.scoreflex_panel_height)));
    }

    // Set our background color
    setBackgroundColor(getContext().getResources().getColor(R.color.scoreflex_background_color));

    // Create the top bar
    View topBar = new View(getContext());
    topBar.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            getResources().getDimensionPixelSize(R.dimen.scoreflex_topbar_height), Gravity.TOP));
    topBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.scoreflex_gradient_background));
    addView(topBar);

    // Create the retry button
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    mErrorLayout = (ViewGroup) inflater.inflate(R.layout.scoreflex_error_layout, null);
    if (mErrorLayout != null) {

        // Configure refresh button
        Button refreshButton = (Button) mErrorLayout.findViewById(R.id.scoreflex_retry_button);
        if (null != refreshButton) {
            refreshButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    if (null == Scoreflex.getPlayerId()) {
                        setUserInterfaceState(new LoadingState());
                        loadUrlAfterLoggedIn(mInitialResource, mInitialRequestParams);
                    } else if (null == mWebView.getUrl()) {
                        setResource(mInitialResource);
                    } else {
                        mWebView.reload();
                    }
                }
            });
        }

        // Configure cancel button
        Button cancelButton = (Button) mErrorLayout.findViewById(R.id.scoreflex_cancel_button);
        if (null != cancelButton) {
            cancelButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    close();
                }
            });
        }

        // Get hold of the message view
        mMessageView = (TextView) mErrorLayout.findViewById(R.id.scoreflex_error_message_view);
        addView(mErrorLayout);

    }

    // Create the close button
    mCloseButton = new ImageButton(getContext());
    Drawable closeButtonDrawable = getResources().getDrawable(R.drawable.scoreflex_close_button);
    int closeButtonMargin = (int) ((getResources().getDimensionPixelSize(R.dimen.scoreflex_topbar_height)
            - closeButtonDrawable.getIntrinsicHeight()) / 2.0f);
    FrameLayout.LayoutParams closeButtonLayoutParams = new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT,
            Gravity.TOP | Gravity.RIGHT);
    closeButtonLayoutParams.setMargins(0, closeButtonMargin, closeButtonMargin, 0);
    mCloseButton.setLayoutParams(closeButtonLayoutParams);
    mCloseButton.setImageDrawable(closeButtonDrawable);
    mCloseButton.setBackgroundDrawable(null);
    mCloseButton.setPadding(0, 0, 0, 0);
    mCloseButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            close();
        }
    });
    addView(mCloseButton);

    // Create the web view
    mWebView = new WebView(mParentActivity);
    mWebView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    // mWebView.setBackgroundColor(Color.RED);
    mWebView.setWebViewClient(new ScoreflexWebViewClient());
    mWebView.setWebChromeClient(new WebChromeClient() {

        @Override
        public boolean onConsoleMessage(ConsoleMessage cm) {
            Log.d("Scoreflex", "javascript Error: "
                    + String.format("%s @ %d: %s", cm.message(), cm.lineNumber(), cm.sourceId()));
            return true;
        }

        public void openFileChooser(ValueCallback<Uri> uploadMsg) {
            // mtbActivity.mUploadMessage = uploadMsg;
            mUploadMessage = uploadMsg;

            String fileName = "picture.jpg";
            ContentValues values = new ContentValues();
            values.put(MediaStore.Images.Media.TITLE, fileName);
            // mOutputFileUri = mParentActivity.getContentResolver().insert(
            // MediaStore.Images.Media.DATA, values);
            final List<Intent> cameraIntents = new ArrayList<Intent>();
            final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            final PackageManager packageManager = mParentActivity.getPackageManager();
            final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
            for (ResolveInfo res : listCam) {
                final String packageName = res.activityInfo.packageName;
                final Intent intent = new Intent(captureIntent);
                intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
                intent.setPackage(packageName);
                cameraIntents.add(intent);
            }

            // Filesystem.
            final Intent galleryIntent = new Intent();
            galleryIntent.setType("image/*");
            galleryIntent.setAction(Intent.ACTION_GET_CONTENT);

            // Chooser of filesystem options.
            final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source please");

            // Add the camera options.
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[] {}));

            mParentActivity.startActivityForResult(chooserIntent, Scoreflex.FILECHOOSER_RESULTCODE);
        }

        public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
            openFileChooser(uploadMsg);
        }

        public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
            openFileChooser(uploadMsg);
        }
    });
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setDomStorageEnabled(true);
    mWebView.getSettings().setDatabasePath(
            getContext().getFilesDir().getPath() + "/data/" + getContext().getPackageName() + "/databases/");
    addView(mWebView);

    TypedArray a = mParentActivity.obtainStyledAttributes(attrs, R.styleable.ScoreflexView, defStyle, 0);
    String resource = a.getString(R.styleable.ScoreflexView_resource);
    if (null != resource)
        setResource(resource);

    a.recycle();

    // Create the animated spinner

    mProgressBar = (ProgressBar) ((LayoutInflater) getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.scoreflex_progress_bar, null);
    mProgressBar.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER));
    addView(mProgressBar);
    LocalBroadcastManager.getInstance(activity).registerReceiver(mLoginReceiver,
            new IntentFilter(Scoreflex.INTENT_USER_LOGED_IN));
    setUserInterfaceState(new InitialState());
}

From source file:com.doplgangr.secrecy.views.FileViewer.java

private Intent generateCustomChooserIntent(Intent prototype, ArrayList<Uri> uris) {
    List<Intent> targetedShareIntents = new ArrayList<Intent>();
    List<HashMap<String, String>> intentMetaInfo = new ArrayList<HashMap<String, String>>();
    Intent chooserIntent;/*  w w w  .  j  ava  2  s. c  o m*/

    Intent dummy = new Intent(prototype.getAction());
    dummy.setType(prototype.getType());
    List<ResolveInfo> resInfo = context.getPackageManager().queryIntentActivities(dummy, 0);

    if (!resInfo.isEmpty()) {
        for (ResolveInfo resolveInfo : resInfo) {
            if (resolveInfo.activityInfo == null
                    || resolveInfo.activityInfo.packageName.equalsIgnoreCase("com.doplgangr.secrecy"))
                continue;

            HashMap<String, String> info = new HashMap<String, String>();
            info.put("packageName", resolveInfo.activityInfo.packageName);
            info.put("className", resolveInfo.activityInfo.name);
            info.put("simpleName",
                    String.valueOf(resolveInfo.activityInfo.loadLabel(context.getPackageManager())));
            intentMetaInfo.add(info);
            for (Uri uri : uris)
                context.grantUriPermission(resolveInfo.activityInfo.packageName, uri,
                        Intent.FLAG_GRANT_READ_URI_PERMISSION);
        }

        if (!intentMetaInfo.isEmpty()) {
            // sorting for nice readability
            Collections.sort(intentMetaInfo, new Comparator<HashMap<String, String>>() {
                @Override
                public int compare(HashMap<String, String> map, HashMap<String, String> map2) {
                    return map.get("simpleName").compareTo(map2.get("simpleName"));
                }
            });

            // create the custom intent list
            for (HashMap<String, String> metaInfo : intentMetaInfo) {
                Intent targetedShareIntent = (Intent) prototype.clone();
                targetedShareIntent.setPackage(metaInfo.get("packageName"));
                targetedShareIntent.setClassName(metaInfo.get("packageName"), metaInfo.get("className"));
                targetedShareIntents.add(targetedShareIntent);
            }
            chooserIntent = Intent.createChooser(targetedShareIntents.remove(targetedShareIntents.size() - 1),
                    CustomApp.context.getString(R.string.Dialog__send_file));
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
                    targetedShareIntents.toArray(new Parcelable[targetedShareIntents.size()]));
            return chooserIntent;
        }
    }

    return new Intent(Intent.ACTION_SEND); //Unable to do anything. Duh.
}

From source file:org.kontalk.ui.ContactsListFragment.java

private void startInvite() {
    Context ctx = getActivity();/*from w  ww  . ja v  a2s .  c  o m*/
    Intent shareIntent = SystemUtils.externalIntent(Intent.ACTION_SEND);
    shareIntent.setType(TextComponent.MIME_TYPE);
    shareIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.text_invite_message));

    List<ResolveInfo> resInfo = ctx.getPackageManager().queryIntentActivities(shareIntent, 0);
    // having size=1 means that we are the only handlers
    if (resInfo != null && resInfo.size() > 1) {
        List<Intent> targets = new ArrayList<>();

        for (ResolveInfo resolveInfo : resInfo) {
            String packageName = resolveInfo.activityInfo.packageName;

            if (!ctx.getPackageName().equals(packageName)) {
                // copy intent and add resolved info
                Intent targetShareIntent = new Intent(shareIntent);
                targetShareIntent.setPackage(packageName)
                        .setComponent(new ComponentName(packageName, resolveInfo.activityInfo.name))
                        .putExtra("org.kontalk.invite.label",
                                resolveInfo.activityInfo.loadLabel(ctx.getPackageManager()));

                targets.add(targetShareIntent);
            }
        }

        if (targets.size() > 0) {
            // initial intents are added before the main intent, so we remove the last one here
            Intent chooser = Intent.createChooser(targets.remove(targets.size() - 1),
                    getString(R.string.menu_invite));
            if (targets.size() > 0) {
                Collections.sort(targets, new DisplayNameComparator());
                // remove custom extras
                for (Intent intent : targets)
                    intent.removeExtra("org.kontalk.invite.label");

                Parcelable[] extraIntents = targets.toArray(new Parcelable[targets.size()]);
                chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
            }

            startActivity(chooser);
            return;
        }
    }

    // no activity to handle invitation
    Toast.makeText(ctx, R.string.warn_invite_no_app, Toast.LENGTH_SHORT).show();
}

From source file:dentex.youtube.downloader.utils.Utils.java

public static Intent createEmailOnlyChooserIntent(Context ctx, Intent source, CharSequence chooserTitle) {
    BugSenseHandler.leaveBreadcrumb("createEmailOnlyChooserIntent");
    Stack<Intent> intents = new Stack<Intent>();
    Intent i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "info@domain.com", null));
    List<ResolveInfo> activities = ctx.getPackageManager().queryIntentActivities(i, 0);

    for (ResolveInfo ri : activities) {
        Intent target = new Intent(source);
        target.setPackage(ri.activityInfo.packageName);
        intents.add(target);//  ww w  .  j  a v a 2  s  .  c o m
    }

    if (!intents.isEmpty()) {
        Intent chooserIntent = Intent.createChooser(intents.remove(0), chooserTitle);
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intents.toArray(new Parcelable[intents.size()]));

        return chooserIntent;
    } else {
        return Intent.createChooser(source, chooserTitle);
    }
}

From source file:com.vuze.android.remote.AndroidUtils.java

public static void openFileChooser(Activity activity, String mimeType, int requestCode) {

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType(mimeType);/*ww w. j a v  a 2  s.co m*/
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    // special intent for Samsung file manager
    Intent sIntent = new Intent("com.sec.android.app.myfiles.PICK_DATA");

    sIntent.putExtra("CONTENT_TYPE", mimeType);
    sIntent.addCategory(Intent.CATEGORY_DEFAULT);

    Intent chooserIntent;
    if (activity.getPackageManager().resolveActivity(sIntent, 0) != null) {
        chooserIntent = Intent.createChooser(sIntent, "Open file");
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { intent });
    } else {
        chooserIntent = Intent.createChooser(intent, "Open file");
    }

    if (chooserIntent != null) {
        try {
            activity.startActivityForResult(chooserIntent, requestCode);
            return;
        } catch (android.content.ActivityNotFoundException ex) {
        }
    }
    Toast.makeText(activity.getApplicationContext(),
            activity.getResources().getString(R.string.no_file_chooser), Toast.LENGTH_SHORT).show();
}

From source file:org.linphone.ContactEditorFragment.java

private void pickImage() {
    imageToUploadUri = null;//from  w  ww.ja  va  2s . c  om
    final List<Intent> cameraIntents = new ArrayList<Intent>();
    final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File file = new File(Environment.getExternalStorageDirectory(), getString(R.string.temp_photo_name));
    imageToUploadUri = Uri.fromFile(file);
    captureIntent.putExtra("crop", "true");
    captureIntent.putExtra("outputX", 256);
    captureIntent.putExtra("outputY", 256);
    captureIntent.putExtra("aspectX", 0);
    captureIntent.putExtra("aspectY", 0);
    captureIntent.putExtra("scale", true);
    captureIntent.putExtra("return-data", false);
    captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageToUploadUri);
    cameraIntents.add(captureIntent);

    final Intent galleryIntent = new Intent();
    galleryIntent.setType("image/*");
    galleryIntent.setAction(Intent.ACTION_GET_CONTENT);

    final Intent chooserIntent = Intent.createChooser(galleryIntent, getString(R.string.image_picker_title));
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[] {}));

    startActivityForResult(chooserIntent, ADD_PHOTO);
}

From source file:org.awesomeapp.messenger.ui.ConversationDetailActivity.java

/**
 * Create a chooser intent to select the source to get image from.<br/>
 * The source can be camera's (ACTION_IMAGE_CAPTURE) or gallery's (ACTION_GET_CONTENT).<br/>
 * All possible sources are added to the intent chooser.
 *///from   w  w w .  j  av a 2 s. co  m
public Intent getPickImageChooserIntent() {

    List<Intent> allIntents = new ArrayList<>();
    PackageManager packageManager = getPackageManager();

    // collect all gallery intents
    Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT);
    galleryIntent.setType("image/*");
    List<ResolveInfo> listGallery = packageManager.queryIntentActivities(galleryIntent, 0);
    for (ResolveInfo res : listGallery) {
        Intent intent = new Intent(galleryIntent);
        intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
        intent.setPackage(res.activityInfo.packageName);
        allIntents.add(intent);
    }

    // the main intent is the last in the list (fucking android) so pickup the useless one
    Intent mainIntent = allIntents.get(allIntents.size() - 1);
    for (Intent intent : allIntents) {
        if (intent.getComponent().getClassName().equals("com.android.documentsui.DocumentsActivity")) {
            mainIntent = intent;
            break;
        }
    }
    allIntents.remove(mainIntent);

    // Create a chooser from the main intent
    Intent chooserIntent = Intent.createChooser(mainIntent, getString(R.string.choose_photos));

    // Add all other intents
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, allIntents.toArray(new Parcelable[allIntents.size()]));

    return chooserIntent;
}

From source file:org.skt.runtime.RuntimeChromeClient.java

private Intent createChooserIntent(Intent... intents) {
    Intent chooser = new Intent(Intent.ACTION_CHOOSER);
    chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, intents);
    chooser.putExtra(Intent.EXTRA_TITLE, "Select Application");
    return chooser;
}

From source file:com.raspi.chatapp.ui.chatting.ChatActivity.java

public void sendLibraryImage(View view) {
    // hide the popup
    View v = findViewById(R.id.popup_layout);
    if (v != null) {
        v.setVisibility(View.GONE);
        attachPopup = false;/* www.ja  va 2  s. co  m*/
    }
    // when clicking attack the user should at first select an application to
    // choose the image with and then choose an image.
    // this intent is for getting the image
    Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT);
    getIntent.setType("image/*");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
        getIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);

    // and this for getting the application to get the image with
    Intent pickIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    pickIntent.setType("image/*");

    // and this finally is for opening the chooserIntent for opening the
    // getIntent for returning the image uri. Yep, thanks android
    Intent chooserIntent = Intent.createChooser(getIntent, getResources().getString(R.string.select_image));
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { pickIntent });
    startActivityForResult(chooserIntent, SEND_LIBRARY_IMAGE_REQUEST_CODE);
    // nope I don't want to be asked for a pwd when selected the image
    getSharedPreferences(Constants.PREFERENCES, 0).edit().putBoolean(Constants.PWD_REQUEST, false).apply();
}