Search code examples
androidandroid-contentproviderinstagram

Image Broken while sharing through Instagram using Android Content Provider


I've used Content Provider for sending files in Uri. I've used the below code for doing this :

public Uri fileSharingUsingContentProvider(File tempFile)
{
 String filePath = tempFile.getAbsolutePath(); // tempFile is the image file ....
 Cursor mCursor = this.getApplicationContext().getContentResolver().query(
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            new String[] { MediaStore.Images.Media._ID },
            MediaStore.Images.Media.DATA + "=? ",
            new String[] { filePath }, null);


  if(mCursor != null && mCursor.moveToFirst()){

        int id = mCursor.getInt(mCursor.getColumnIndex(MediaStore.MediaColumns._ID));
        Uri baseUri = Uri.parse("content://media/external/images/media");


        Trace.d(TAG,"<==> The baseUri after parsing : " + Uri.withAppendedPath(baseUri, ""+id));
        return Uri.withAppendedPath(baseUri, "" + id);
  }
  else {
        if (tempFile.exists()) {
            ContentValues values = new ContentValues();
            values.put(MediaStore.Images.Media.DATA, filePath);

            return this.getApplicationContext().getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        } 
        else {
            return null;
        }
   }
}

But the problem is, while I try to share via Instagram, this code perfectly works for all devices except Galaxy Note 2 where the image file is broken. I've tried several ways but failed to fix the problem. If anybody has any idea regarding this thing , please help me.

Thanks in advance.


Solution

  • After a long research, I finally figure out a way to solve this problem. In a part of the app that I'm currently working on, I've to download the images in the smart phone internal storage. However, if the picture resolution is high like (6480 x 4320) pixel then the Galaxy Note 2 is failed to upload the image in Instagram. But for low resolution images it is working perfectly. I guess while downloading the image, I've to fix the image resolution. So, if anyone facing this type of issues, you must concentrate upon the image size at first.

    Another important issue is, this image size problem is only occurred in Galaxy Note 2. For other devices there is no problem while uploading the images in Instagram.