Click here to Skip to main content
15,902,830 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I able to use the following code to get image from Dropbox, it opens up Droxbox and is able to select and download the image. However, the issue is that the downloaded image is not able to be show on the ImageView. Please help, Thank you.

If my method does not work, please suggest other ways that i can used to get image from dropbox to the imageview. Thank You.

What I have tried:

Code: getImage

Image.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub

                List<String> data= new ArrayList<String>();
                data.add("Import from local device.");
                data.add("Take camera image.");

                AdapterGetImage adapter = new AdapterGetImage(CropImageActivity.this);


                new AlertDialog.Builder(CropImageActivity.this).setAdapter(adapter, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {

                        if (which==0) {
                            final Intent intent = new Intent();
                            startActivityForResult(Intent.createChooser(intent, "Select File"),GALLERY_CHOOSER_INTENT);
                        else if(which==1)

                            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                            if (intent.resolveActivity(getPackageManager()) !=null)
                                File photoFile = null;
                                    photoFile = createImageFile();
                                catch (IOException ex)
                                if (photoFile !=null)
                                    Uri photoURI = FileProvider.getUriForFile(CropImageActivity.this,



                }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {


Code: get path of image
public static String getPath(final Context context, final Uri uri) {

        // check here to KITKAT or new version
        final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;

        // DocumentProvider
        if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {

            // ExternalStorageProvider
            if (isExternalStorageDocument(uri)) {
                final String docId = DocumentsContract.getDocumentId(uri);
                final String[] split = docId.split(":");
                final String type = split[0];

                if ("primary".equalsIgnoreCase(type)) {
                    return Environment.getExternalStorageDirectory() + "/"
                            + split[1];
            // DownloadsProvider
            else if (isDownloadsDocument(uri)) {

                final String id = DocumentsContract.getDocumentId(uri);
                final Uri contentUri = ContentUris.withAppendedId(

                return getDataColumn(context, contentUri, null, null);
            // MediaProvider
            else if (isMediaDocument(uri)) {
                final String docId = DocumentsContract.getDocumentId(uri);
                final String[] split = docId.split(":");
                final String type = split[0];

                Uri contentUri = null;
                if ("image".equals(type)) {
                    contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
                } else if ("video".equals(type)) {
                    contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
                } else if ("audio".equals(type)) {
                    contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;

                final String selection = "_id=?";
                final String[] selectionArgs = new String[] { split[1] };

                return getDataColumn(context, contentUri, selection,
        // MediaStore (and general)
        else if ("content".equalsIgnoreCase(uri.getScheme())) {

            // Return the remote address
            if (isGooglePhotosUri(uri))
                return uri.getLastPathSegment();

            return getDataColumn(context, uri, null, null);
        // File
        else if ("file".equalsIgnoreCase(uri.getScheme())) {
            return uri.getPath();

        return null;

Code: Activity result
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        try {

            if (requestCode == GALLERY_CHOOSER_INTENT) {
                if (null == data) return;

                String selectedImagePath;
                Uri selectedImageUri = data.getData();

                //MEDIA GALLERY
                selectedImagePath = getPath(getApplicationContext(), selectedImageUri);

                Toast.makeText(this,"uri" +selectedImagePath,Toast.LENGTH_LONG).show();


        catch (Throwable ex) {
            AlertDialog.Builder builder = new AlertDialog.Builder(ImageActivity.this);
            builder.setMessage("We apologize for the inconvenience caused, data" +data.getData()
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int id) {
                                    Intent goToStart = new Intent(

            AlertDialog alert = builder.create();

David Crow 3-Oct-18 9:10am    
An image is an image, regardless from whence it came. If you know the image was successfully downloaded, or if your "show image" code can show other arbitrary images that exist on your device, Dropbox can be removed from the equation. Do what you can to eliminate irrelevant things, and focus on what you are left with.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900