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:io.hypertrack.sendeta.util.images.EasyImage.java

private static Intent createChooserIntent(Context context, String chooserTitle, boolean showGallery)
        throws IOException {
    Uri outputFileUri = createCameraPictureFile(context);
    List<Intent> cameraIntents = new ArrayList<>();
    Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    PackageManager packageManager = context.getPackageManager();
    List<ResolveInfo> camList = packageManager.queryIntentActivities(captureIntent, 0);
    for (ResolveInfo res : camList) {
        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);/*from  ww w.  ja v a 2s. c  o m*/
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        cameraIntents.add(intent);
    }
    Intent galleryIntent;

    if (showGallery) {
        galleryIntent = createGalleryIntent();
    } else {
        galleryIntent = createDocumentsIntent();
    }

    Intent chooserIntent = Intent.createChooser(galleryIntent, chooserTitle);
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
            cameraIntents.toArray(new Parcelable[cameraIntents.size()]));

    return chooserIntent;
}

From source file:io.github.hidroh.materialistic.AppUtils.java

public static void openWebUrlExternal(Context context, WebItem item, String url, CustomTabsSession session) {
    if (!hasConnection(context)) {
        context.startActivity(/*  ww w.  ja v  a  2  s  . co m*/
                new Intent(context, OfflineWebActivity.class).putExtra(OfflineWebActivity.EXTRA_URL, url));
        return;
    }
    Intent intent = createViewIntent(context, item, url, session);
    if (!HackerNewsClient.BASE_WEB_URL.contains(Uri.parse(url).getHost())) {
        if (intent.resolveActivity(context.getPackageManager()) != null) {
            context.startActivity(intent);
        }
        return;
    }
    List<ResolveInfo> activities = context.getPackageManager().queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    ArrayList<Intent> intents = new ArrayList<>();
    for (ResolveInfo info : activities) {
        if (info.activityInfo.packageName.equalsIgnoreCase(context.getPackageName())) {
            continue;
        }
        intents.add(createViewIntent(context, item, url, session).setPackage(info.activityInfo.packageName));
    }
    if (intents.isEmpty()) {
        return;
    }
    if (intents.size() == 1) {
        context.startActivity(intents.remove(0));
    } else {
        context.startActivity(Intent.createChooser(intents.remove(0), context.getString(R.string.chooser_title))
                .putExtra(Intent.EXTRA_INITIAL_INTENTS, intents.toArray(new Parcelable[intents.size()])));
    }
}

From source file:com.mvc.imagepicker.ImagePicker.java

/**
 * Get an Intent which will launch a dialog to pick an image from camera/gallery apps.
 *
 * @param context      context.// w w  w.  j a  v a 2 s  .co m
 * @param chooserTitle will appear on the picker dialog.
 * @return intent launcher.
 */
public static Intent getPickImageIntent(Context context, String chooserTitle) {
    Intent chooserIntent = null;
    List<Intent> intentList = new ArrayList<>();

    Intent pickIntent = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    intentList = addIntentsToList(context, intentList, pickIntent);

    // Camera action will fail if the app does not have permission, check before adding intent.
    // We only need to add the camera intent if the app does not use the CAMERA permission
    // in the androidmanifest.xml
    // Or if the user has granted access to the camera.
    // See https://developer.android.com/reference/android/provider/MediaStore.html#ACTION_IMAGE_CAPTURE
    if (!appManifestContainsPermission(context, Manifest.permission.CAMERA) || hasCameraAccess(context)) {
        Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        takePhotoIntent.putExtra("return-data", true);
        takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(getTemporalFile(context)));
        intentList = addIntentsToList(context, intentList, takePhotoIntent);
    }

    if (intentList.size() > 0) {
        chooserIntent = Intent.createChooser(intentList.remove(intentList.size() - 1), chooserTitle);
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
                intentList.toArray(new Parcelable[intentList.size()]));
    }

    return chooserIntent;
}

From source file:com.ruesga.rview.misc.ActivityHelper.java

@SuppressWarnings("Convert2streamapi")
public static void openUri(Context ctx, Uri uri, boolean excludeRview) {
    try {/*from   ww w .j av  a2  s .  co m*/
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        intent.putExtra(Constants.EXTRA_FORCE_SINGLE_PANEL, true);
        intent.putExtra(Constants.EXTRA_SOURCE, ctx.getPackageName());

        if (excludeRview) {
            // Use a different url to find all the browsers activities
            Intent test = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.es"));
            PackageManager pm = ctx.getPackageManager();
            List<ResolveInfo> activities = pm.queryIntentActivities(test, PackageManager.MATCH_DEFAULT_ONLY);

            List<Intent> targetIntents = new ArrayList<>();
            for (ResolveInfo ri : activities) {
                if (!ri.activityInfo.packageName.equals(ctx.getPackageName())) {
                    Intent i = new Intent(Intent.ACTION_VIEW, uri);
                    i.setPackage(ri.activityInfo.packageName);
                    i.putExtra(Constants.EXTRA_SOURCE, ctx.getPackageName());
                    i.putExtra(Constants.EXTRA_FORCE_SINGLE_PANEL, true);
                    targetIntents.add(i);
                }
            }

            if (targetIntents.size() == 0) {
                throw new ActivityNotFoundException();
            } else if (targetIntents.size() == 1) {
                ctx.startActivity(targetIntents.get(0));
            } else {
                Intent chooserIntent = Intent.createChooser(intent, ctx.getString(R.string.action_open_with));
                chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
                        targetIntents.toArray(new Parcelable[] {}));
                ctx.startActivity(chooserIntent);
            }
        } else {
            ctx.startActivity(intent);
        }

    } catch (ActivityNotFoundException ex) {
        // Fallback to default browser
        String msg = ctx.getString(R.string.exception_browser_not_found, uri.toString());
        Toast.makeText(ctx, msg, Toast.LENGTH_SHORT).show();
    }
}

From source file:com.duy.ascii.sharedcode.image.ImageToAsciiActivity.java

private void selectImage() {
    if (!permissionGrated()) {
        return;//from  www.  j  a v a2 s .  c o  m
    }
    Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT);
    getIntent.setType("image/*");
    Intent pickIntent = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    pickIntent.setType("image/*");
    Intent chooserIntent = Intent.createChooser(getIntent, "Select Image");
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { pickIntent });
    startActivityForResult(chooserIntent, PICK_IMAGE);
}

From source file:com.ieeecsvit.riviera17android.activity.MainActivity.java

public Intent createEmailOnlyChooserIntent(Intent source, CharSequence chooserTitle) {
    Stack<Intent> intents = new Stack<Intent>();
    Intent i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "tushar.narula17@live.com", null));
    List<ResolveInfo> activities = getPackageManager().queryIntentActivities(i, 0);

    for (ResolveInfo ri : activities) {
        Intent target = new Intent(source);
        target.setPackage(ri.activityInfo.packageName);
        intents.add(target);//from  ww w .  j  a  v a 2s. co 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:Rangoli.testapp.Feed.NewPostActivity.java

@AfterPermissionGranted(RC_CAMERA_PERMISSIONS)
private void showImagePicker() {
    // Check for camera permissions
    if (!EasyPermissions.hasPermissions(this, cameraPerms)) {
        EasyPermissions.requestPermissions(this, "This sample will upload a picture from your Camera",
                RC_CAMERA_PERMISSIONS, cameraPerms);
        return;/*  w  w  w  . j a v  a 2 s.co  m*/
    }

    // Choose file storage location
    File file = new File(getExternalCacheDir(), UUID.randomUUID().toString());
    mFileUri = Uri.fromFile(file);

    // Camera
    final List<Intent> cameraIntents = new ArrayList<Intent>();
    final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    final PackageManager packageManager = 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(packageName, res.activityInfo.name));
        intent.setPackage(packageName);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, mFileUri);
        cameraIntents.add(intent);
    }

    // Image Picker
    Intent pickerIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

    Intent chooserIntent = Intent.createChooser(pickerIntent, "");
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
            cameraIntents.toArray(new Parcelable[cameraIntents.size()]));
    startActivityForResult(chooserIntent, TC_PICK_IMAGE);
}

From source file:com.akalizakeza.apps.ishusho.activity.NewPostActivity.java

@AfterPermissionGranted(RC_CAMERA_PERMISSIONS)
private void showImagePicker() {
    // Check for camera permissions
    if (!EasyPermissions.hasPermissions(this, cameraPerms)) {
        EasyPermissions.requestPermissions(this, "This sample will upload a picture from your Camera",
                RC_CAMERA_PERMISSIONS, cameraPerms);
        return;/*ww  w  .  j a  v a2 s  .c  o  m*/
    }

    // Choose file storage location
    File file = new File(getExternalCacheDir(), UUID.randomUUID().toString());
    mFileUri = Uri.fromFile(file);

    // Camera
    final List<Intent> cameraIntents = new ArrayList<Intent>();
    final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    final PackageManager packageManager = 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(packageName, res.activityInfo.name));
        intent.setPackage(packageName);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, mFileUri);
        cameraIntents.add(intent);
    }

    // Image Picker
    Intent pickerIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

    Intent chooserIntent = Intent.createChooser(pickerIntent, getString(R.string.picture_chooser_title));
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
            cameraIntents.toArray(new Parcelable[cameraIntents.size()]));
    startActivityForResult(chooserIntent, TC_PICK_IMAGE);
}

From source file:com.github.dfa.diaspora_android.activity.ShareActivity.java

@SuppressLint("SetJavaScriptEnabled")
@Override//w  w w . ja va 2 s  . com
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main__activity);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (toolbar != null) {
        toolbar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (Helpers.isOnline(ShareActivity.this)) {
                    Intent intent = new Intent(ShareActivity.this, MainActivity.class);
                    startActivityForResult(intent, 100);
                    overridePendingTransition(0, 0);
                    finish();
                } else {
                    Snackbar.make(swipeView, R.string.no_internet, Snackbar.LENGTH_LONG).show();
                }
            }
        });
    }
    setTitle(R.string.new_post);

    progressBar = (ProgressBar) findViewById(R.id.progressBar);

    swipeView = (SwipeRefreshLayout) findViewById(R.id.swipe);
    swipeView.setEnabled(false);

    podDomain = ((App) getApplication()).getSettings().getPodDomain();

    webView = (WebView) findViewById(R.id.webView);
    webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);

    WebSettings wSettings = webView.getSettings();
    wSettings.setJavaScriptEnabled(true);
    wSettings.setBuiltInZoomControls(true);

    if (Build.VERSION.SDK_INT >= 21)
        wSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);

    /*
     * WebViewClient
     */
    webView.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Log.d(TAG, url);
            if (!url.contains(podDomain)) {
                Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(i);
                return true;
            }
            return false;

        }

        public void onPageFinished(WebView view, String url) {
            Log.i(TAG, "Finished loading URL: " + url);
        }
    });

    /*
     * WebChromeClient
     */
    webView.setWebChromeClient(new WebChromeClient() {

        public void onProgressChanged(WebView wv, int progress) {
            progressBar.setProgress(progress);

            if (progress > 0 && progress <= 60) {
                Helpers.getNotificationCount(wv);
            }

            if (progress > 60) {
                Helpers.applyDiasporaMobileSiteChanges(wv);
            }

            if (progress == 100) {
                progressBar.setVisibility(View.GONE);
            } else {
                progressBar.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
                FileChooserParams fileChooserParams) {
            if (mFilePathCallback != null)
                mFilePathCallback.onReceiveValue(null);

            mFilePathCallback = filePathCallback;

            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
                // Create the File where the photo should go
                File photoFile = null;
                try {
                    photoFile = createImageFile();
                    takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
                } catch (IOException ex) {
                    // Error occurred while creating the File
                    Snackbar.make(getWindow().findViewById(R.id.main__layout), "Unable to get image",
                            Snackbar.LENGTH_LONG).show();
                }

                // Continue only if the File was successfully created
                if (photoFile != null) {
                    mCameraPhotoPath = "file:" + photoFile.getAbsolutePath();
                    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
                } else {
                    takePictureIntent = null;
                }
            }

            Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
            contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
            contentSelectionIntent.setType("image/*");

            Intent[] intentArray;
            if (takePictureIntent != null) {
                intentArray = new Intent[] { takePictureIntent };
            } else {
                intentArray = new Intent[0];
            }

            Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
            chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
            chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);

            startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE);

            return true;
        }
    });

    if (savedInstanceState == null) {
        if (Helpers.isOnline(ShareActivity.this)) {
            webView.loadUrl("https://" + podDomain + "/status_messages/new");
        } else {
            Snackbar.make(getWindow().findViewById(R.id.main__layout), R.string.no_internet,
                    Snackbar.LENGTH_LONG).show();
        }
    }

    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();

    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if ("text/plain".equals(type)) {
            if (intent.hasExtra(Intent.EXTRA_SUBJECT)) {
                handleSendSubject(intent);
            } else {
                handleSendText(intent);
            }
        } else if (type.startsWith("image/")) {
            // TODO Handle single image being sent -> see manifest
            handleSendImage(intent);
        }
        //} else {
        // Handle other intents, such as being started from the home screen
    }

}