Example usage for android.content Intent ACTION_GET_CONTENT

List of usage examples for android.content Intent ACTION_GET_CONTENT

Introduction

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

Prototype

String ACTION_GET_CONTENT

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

Click Source Link

Document

Activity Action: Allow the user to select a particular kind of data and return it.

Usage

From source file:com.visenze.visearch.camerademo.fragments.CameraFragment.java

@OnClick(R.id.camera_album_button)
public void openGallery() {
    Intent openAlbumIntent = new Intent(Intent.ACTION_GET_CONTENT);
    openAlbumIntent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
    startActivityForResult(openAlbumIntent, RESULT_LOAD_IMAGE_FROM_GALLERY);
}

From source file:org.skt.runtime.original.CameraLauncher.java

/**
 * Get image from photo library./*from  w  w w  .  ja  va  2  s .c om*/
 * 
 * @param quality           Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
 * @param srcType           The album to get image from.
 * @param returnType        Set the type of image to return. 
 */
// TODO: Images selected from SDCARD don't display correctly, but from CAMERA ALBUM do!
public void getImage(int srcType, int returnType) {
    Intent intent = new Intent();
    String title = GET_PICTURE;
    if (this.mediaType == PICTURE) {
        intent.setType("image/*");
    } else if (this.mediaType == VIDEO) {
        intent.setType("video/*");
        title = GET_VIDEO;
    } else if (this.mediaType == ALLMEDIA) {
        // I wanted to make the type 'image/*, video/*' but this does not work on all versions 
        // of android so I had to go with the wildcard search.
        intent.setType("*/*");
        title = GET_All;
    }

    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    this.ctx.startActivityForResult((Plugin) this, Intent.createChooser(intent, new String(title)),
            (srcType + 1) * 16 + returnType + 1);
}

From source file:com.mifos.mifosxdroid.dialogfragments.documentdialog.DocumentDialogFragment.java

/**
 * This method is to start an intent(getExternal Storage Document).
 * If Android Version is Kitkat or greater then start intent with ACTION_OPEN_DOCUMENT,
 * otherwise with ACTION_GET_CONTENT/* w w w. j a  v  a 2 s  . c  om*/
 */
@Override
public void getExternalStorageDocument() {
    Intent intentDocument;
    if (AndroidVersionUtil.isApiVersionGreaterOrEqual(Build.VERSION_CODES.KITKAT)) {
        intentDocument = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    } else {
        intentDocument = new Intent(Intent.ACTION_GET_CONTENT);
    }
    intentDocument.addCategory(Intent.CATEGORY_OPENABLE);
    intentDocument.setType("*/*");
    startActivityForResult(intentDocument, FILE_SELECT_CODE);
}

From source file:com.stfalcon.contentmanager.ContentManager.java

/**
 * Pick image or video content from storage or google acc
 *
 * @param content image or video/*w w  w  .j  a  v a2  s.co  m*/
 */
public void pickContent(Content content) {
    savedTask = CONTENT_PICKER;
    savedContent = content;
    if (isStoragePermissionGranted(activity, fragment)) {
        this.targetFile = createFile(content);
        if (Build.VERSION.SDK_INT < 19) {
            Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
            photoPickerIntent.setType(content.toString());
            if (fragment == null) {
                activity.startActivityForResult(photoPickerIntent, CONTENT_PICKER);
            } else {
                fragment.startActivityForResult(photoPickerIntent, CONTENT_PICKER);
            }
        } else {
            Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
            photoPickerIntent.setType(content.toString());
            photoPickerIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            photoPickerIntent.addCategory(Intent.CATEGORY_OPENABLE);
            if (photoPickerIntent.resolveActivity(activity.getPackageManager()) != null) {
                if (fragment == null) {
                    activity.startActivityForResult(photoPickerIntent, CONTENT_PICKER);
                } else {
                    fragment.startActivityForResult(photoPickerIntent, CONTENT_PICKER);
                }
            }
        }
    }
}

From source file:de.stadtrallye.rallyesoft.model.pictures.PictureManager.java

/**
 * Get an intent to either take a picture with the camera app or select an app that can pick an existing picture
 *///from  ww w  .j ava  2  s.co m
public Intent startPictureTakeOrSelect(SourceHint sourceHint) {
    //Attention: Our RequestCode will not be used for the result, if a jpeg is picked, data.getType will contain image/jpeg, if the picture was just taken with the camera it will be null
    Intent pickIntent = new Intent();
    pickIntent.setType("image/jpeg");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        pickIntent.setAction(Intent.ACTION_OPEN_DOCUMENT);
        pickIntent.addCategory(Intent.CATEGORY_OPENABLE);
    } else {
        pickIntent.setAction(Intent.ACTION_GET_CONTENT);
    }

    Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    Uri fileUri = getPicturePlaceholderUri(PictureManager.MEDIA_TYPE_IMAGE, sourceHint); // reserve a filename to save the image
    takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
    takePhotoIntent.putExtra("return-data", true);

    Intent chooserIntent = Intent.createChooser(pickIntent, context.getString(R.string.select_take_picture));
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { takePhotoIntent });

    return chooserIntent;
}

From source file:ar.com.tristeslostrestigres.diasporanativewebapp.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    progressBar = findViewById(R.id.progressBar);

    pm = new PrefManager(MainActivity.this);

    SharedPreferences config = getSharedPreferences("PodSettings", MODE_PRIVATE);
    podDomain = config.getString("podDomain", null);

    fab = findViewById(R.id.multiple_actions);
    fab.setVisibility(View.GONE);

    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from   w w w  .jav  a  2 s . co  m
    getSupportActionBar().setTitle(null);

    txtTitle = (TextView) findViewById(R.id.toolbar_title);
    txtTitle.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (Helpers.isOnline(MainActivity.this)) {
                txtTitle.setText(R.string.jb_stream);
                webView.loadUrl("https://" + podDomain + "/stream");
            } else {
                Snackbar.make(v, R.string.no_internet, Snackbar.LENGTH_SHORT).show();
            }
        }
    });

    webView = findViewById(R.id.webView);
    webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    webView.addJavascriptInterface(new JavaScriptInterface(), "NotificationCounter");

    if (savedInstanceState != null) {
        webView.restoreState(savedInstanceState);
    }

    wSettings = webView.getSettings();
    wSettings.setJavaScriptEnabled(true);
    wSettings.setUseWideViewPort(true);
    wSettings.setLoadWithOverviewMode(true);
    wSettings.setDomStorageEnabled(true);
    wSettings.setMinimumFontSize(pm.getMinimumFontSize());
    wSettings.setLoadsImagesAutomatically(pm.getLoadImages());

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

    /*
     * WebViewClient
     */
    webView.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String 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) {
            if (url.contains("/new") || url.contains("/sign_in")) {
                fab.setVisibility(View.GONE);
            } else {
                fab.setVisibility(View.VISIBLE);
            }
        }

        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            new AlertDialog.Builder(MainActivity.this).setIcon(android.R.drawable.ic_dialog_alert)
                    .setMessage(description).setPositiveButton("CLOSE", null).show();
        }
    });

    /*
     * 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.hideTopBar(wv);
                fab.setVisibility(View.VISIBLE);
            }

            if (progress == 100) {
                fab.collapse();
                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.drawer), "Unable to get image",
                            Snackbar.LENGTH_SHORT).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;
        }

        public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
            return super.onJsAlert(view, url, message, result);
        }
    });

    /*
     * NavigationView
     */
    NavigationView navigationView = findViewById(R.id.navigation_view);
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
            if (menuItem.isChecked())
                menuItem.setChecked(false);
            else
                menuItem.setChecked(true);

            drawerLayout.closeDrawers();

            switch (menuItem.getItemId()) {
            default:
                Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                        Snackbar.LENGTH_SHORT).show();
                return true;

            case R.id.jb_stream:
                if (Helpers.isOnline(MainActivity.this)) {
                    txtTitle.setText(R.string.jb_stream);
                    webView.loadUrl("https://" + podDomain + "/stream");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_public:
                setTitle(R.string.jb_public);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/public");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_liked:
                txtTitle.setText(R.string.jb_liked);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/liked");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_commented:
                txtTitle.setText(R.string.jb_commented);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/commented");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_contacts:
                txtTitle.setText(R.string.jb_contacts);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/contacts");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_mentions:
                txtTitle.setText(R.string.jb_mentions);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/mentions");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_activities:
                txtTitle.setText(R.string.jb_activities);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/activity");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_followed_tags:
                txtTitle.setText(R.string.jb_followed_tags);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/followed_tags");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_manage_tags:

                txtTitle.setText(R.string.jb_manage_tags);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/tag_followings/manage");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_license:
                txtTitle.setText(R.string.jb_license);
                new AlertDialog.Builder(MainActivity.this).setTitle(getString(R.string.license_title))
                        .setMessage(getString(R.string.license_text))
                        .setPositiveButton(getString(R.string.license_yes),
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        Intent i = new Intent(Intent.ACTION_VIEW,
                                                Uri.parse("https://github.com/mdev88/Diaspora-Native-WebApp"));
                                        startActivity(i);
                                        dialog.cancel();
                                    }
                                })
                        .setNegativeButton(getString(R.string.license_no),
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        dialog.cancel();
                                    }
                                })
                        .show();

                return true;

            case R.id.jb_aspects:
                txtTitle.setText(R.string.jb_aspects);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/aspects");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_settings:
                txtTitle.setText(R.string.jb_settings);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/user/edit");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();

                    return false;
                }

            case R.id.jb_pod:
                txtTitle.setText(R.string.jb_pod);
                if (Helpers.isOnline(MainActivity.this)) {
                    new AlertDialog.Builder(MainActivity.this).setTitle(getString(R.string.confirmation))
                            .setMessage(getString(R.string.change_pod_warning))
                            .setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
                                @TargetApi(11)
                                public void onClick(DialogInterface dialog, int id) {
                                    webView.clearCache(true);
                                    dialog.cancel();
                                    Intent i = new Intent(MainActivity.this, PodsActivity.class);
                                    startActivity(i);
                                    finish();
                                }
                            }).setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() {
                                @TargetApi(11)
                                public void onClick(DialogInterface dialog, int id) {
                                    dialog.cancel();
                                }
                            }).show();
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }
            }
        }
    });

    /*
     * DrawerLayout
     */
    drawerLayout = findViewById(R.id.drawer);
    ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar,
            R.string.openDrawer, R.string.closeDrawer);
    drawerLayout.setDrawerListener(actionBarDrawerToggle);
    //calling sync state is necessary or else your hamburger icon wont show up
    actionBarDrawerToggle.syncState();

    if (savedInstanceState == null) {
        if (Helpers.isOnline(MainActivity.this)) {
            webView.loadData("", "text/html", null);
            webView.loadUrl("https://" + podDomain);
        } else {
            Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT)
                    .show();
        }
    }

}

From source file:com.anyonavinfo.commonuserregister.MainActivity.java

/**
 * /*from  w w w .j  a  v  a2  s . co  m*/
 */
private void onOpenImage() {
    /***
     * androidintent? ??
     */
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(intent, 3);
}

From source file:com.fa.mastodon.activity.EditProfileActivity.java

private void initiateMediaPicking() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("image/*");
    switch (currentlyPicking) {
    case AVATAR: {
        startActivityForResult(intent, AVATAR_PICK_RESULT);
        break;/*from w w  w. ja  va  2s  . co  m*/
    }
    case HEADER: {
        startActivityForResult(intent, HEADER_PICK_RESULT);
        break;
    }
    }
}

From source file:app.axe.imooc.zxing.app.CaptureActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (requestCode == MY_PERMISSIONS_REQUEST_CAMERA) {
        if (ContextCompat.checkSelfPermission(this,
                android.Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            //?/*from  www .java 2  s  .  com*/
        } else {
            initCamera(surfaceHolder);
        }
    } else if (requestCode == MY_PERMISSIONS_REQUEST_XIANGCE) {
        if (ContextCompat.checkSelfPermission(CaptureActivity.this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        } else {
            // 
            Intent innerIntent = new Intent(Intent.ACTION_GET_CONTENT); // "android.intent.action.GET_CONTENT"
            innerIntent.setType("image/*");
            Intent wrapperIntent = Intent.createChooser(innerIntent, "?");
            startActivityForResult(wrapperIntent, REQUEST_CODE);
        }
    }
}

From source file:nl.sogeti.android.gpstracker.viewer.TrackList.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    boolean handled = false;
    switch (item.getItemId()) {
    case android.R.id.home:
        NavUtils.navigateUpFromSameTask(this);
        handled = true;//w w w. j av a2  s  .  c o m
        break;
    case MENU_SEARCH:
        onSearchRequested();
        handled = true;
        break;
    case MENU_VACUUM:
        showDialog(DIALOG_VACUUM);
        break;
    case MENU_PICKER:
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("*/*");
        startActivityForResult(intent, FILE_PICKER);
        break;
    default:
        handled = super.onOptionsItemSelected(item);
    }
    return handled;
}