Skip to content Skip to sidebar Skip to footer

Converting Url To Uri And Passing It To Asynctask<>

I am converting a Url to Uri in the following way imgUrl = intent.getStringExtra(getString(R.string.selected_image)); Log.d(TAG, 'Image URL' + imgUrl);

Solution 1:

Please add the 2 Logs with the ++++++++++++ lines in your doInBackGround() and post your Logcat:

@Override
protectedbyte[] doInBackground(Uri... params) {
    Log.d(TAG, "doInBackground: started.");

    Log.d(TAG, "+++++++++++++ params[0]: " + params[0]);

    if(mBitmap == null){
        try{
            mBitmap = MediaStore.Images.Media.getBitmap(NextActivity.this.getContentResolver(), params[0]);
        }catch (IOException e){
            Log.e(TAG, "doInBackground: IOException: " + e.getMessage());
        }
    }

    Log.d(TAG, "+++++++++++++ mBitmap: " + mBitmap);

    byte[] bytes = null;
    Log.d(TAG, "doInBackground: megabytes before compression: " + mBitmap.getByteCount() / 1000000 );
    bytes = getBytesFromBitmap(mBitmap, 100);
    Log.d(TAG, "doInBackground: megabytes before compression: " + bytes.length / 1000000 );
    return bytes;
}

Solution 2:

So as it turns out, Locdoc01 was right all along, the Uri was wrong, all I had to do was append file:// to the url before parsing it into Uri ...

like this

imgUrl = intent.getStringExtra(getString(R.string.selected_image));
ImgUrlAppended = "file://" + imgUrl;
Log.d(TAG, "Image URL" + imgUrl);
imageUri = Uri.parse(ImgUrlAppended) ;
Log.d(TAG, "Image URI" + imageUri);

Image compresses now !

thank you for all the support, StackOverflow ! hope this helps someone

Post a Comment for "Converting Url To Uri And Passing It To Asynctask<>"