简体   繁体   中英

IllegalArgumentException while picking image from gallery on Sony z2

When I run script on Sony Z2 it throws this Exception, although it runs smoothly in Samsung s4:

Caused by: java.lang.IllegalArgumentException: filename cannot be null

at (MyDetailsPage.java:274)

And here is my program and java:274 is in outside code:

 public  Bitmap decodeScaledDownBitmapFromDatabase(String imagePath,int requiredHeight,int requiredWidth){
       final BitmapFactory.Options options=new BitmapFactory.Options();
        options.inJustDecodeBounds=true;
        Bitmap bitmap=BitmapFactory.decodeFile(imagePath, options);
        Matrix matrix;

        options.inSampleSize=calculateInputImageSize(options, requiredHeight, requiredWidth);
        options.inJustDecodeBounds=false;
        bitmap =BitmapFactory.decodeFile(imagePath, options);
        int angel=0;


                    try{

java : 276         ExifInterface exifInterface=new ExifInterface(imagePath);

                   int orientation=exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,ExifInterface.ORIENTATION_UNDEFINED);

                   if (orientation==ExifInterface.ORIENTATION_ROTATE_90){
                   angel=90;
                   }
                   else if(orientation==ExifInterface.ORIENTATION_ROTATE_180){
                angel=180;
            }
            else if (orientation==ExifInterface.ORIENTATION_ROTATE_270){
                angel=270;
            }
        }
        catch (IOException e){
            Toast.makeText(getApplicationContext(),"Image could not be selected",Toast.LENGTH_LONG).show();
        }
        matrix=new Matrix();
        matrix.postRotate(angel);
        Bitmap readyBitmap=Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);

        return readyBitmap;
    }

Ok, It seems ridiculous, just writing answer and hope will help someone. It is really wierd how it affects whole code. When calling intent I used

Intent intent = new Intent();
intent.setAction(Intent.ACTION_PICK);

Instead of

intent.setAction(Intent.ACTION_GET_CONTENT);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM