2016-09-13 19 views
0

これは私のコードですが、私はこのアプリケーションをgg whit android 5で動作させていますが、asus zenfone whit android 6では画面に表示されない画像は "image invalid"と表示されます。ImageViewはAndroid 5で動作しますが、Android 6では動作しませんでした。どうすれば修正できますか?

  selectedImage = null; 
      orientation = -1; 
      selectedImage = data.getData(); 
      String[] filePathColumn = {MediaStore.Images.Media.DATA}; 

      // Get the cursor 
      Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); 
      Cursor cursorF = getContentResolver().query(selectedImage, new String[]{MediaStore.Images.ImageColumns.ORIENTATION}, null, null, null); 
      // Move to first row 
      cursor.moveToFirst(); 

      if (cursorF == null || cursorF.getCount() != 1) { 
       orientation = 90; //Assuming it was taken portrait 
      } else { 
       cursorF.moveToFirst(); 
       orientation = cursorF.getInt(0); 
      } 
      //Toast.makeText(this, "orientation: " + orientation, Toast.LENGTH_LONG).show(); 
      int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
      imgDecodableString = cursor.getString(columnIndex);//imgDecodableString = percorso completo immagine 
      cursor.close(); 

      bmpImage = BitmapFactory.decodeFile(imgDecodableString); 
      bmpImage = RotateBitmap.rotateImageIfRequiredFile(bmpImage, orientation); 

      ImageView imgView = (ImageView) findViewById(R.id.imgView); 
      // Set the Image in ImageView after decoding the String 
      imgView.setImageBitmap(bmpImage); 
      //name of image 
      String sFilePath = getRealPathFromURI(selectedImage); 
      String saPathParts[] = sFilePath.split("/"); 
      String sFileName = saPathParts[saPathParts.length - 1]; 
      filename = sFileName; 
      Toast.makeText(this, "filename:" + filename, Toast.LENGTH_LONG).show(); 
      if (bmpImage == null) { 
       Toast.makeText(getBaseContext(), "Image invalid", Toast.LENGTH_SHORT).show(); 
      } 

     } 

答えて

1

Android 6では、アプリケーションのインストール時ではなく、使用時にアクセス許可を要求する必要があると思います。許可が必要なユーザーストレージにアクセスしているようです。 Android Marshmallowランタイムパーミッションを検索します。

+0

これが原因かもしれませんが、修正方法はわかりません。もっと具体的な提案をいただけますか? –

+0

@PasqualeMoramarcoここをクリックしてください:https://developer.android.com/training/permissions/requesting.html – amitairos

+0

私はこのページを読んだことがありますが、経験はあまりありません。 ?どうもありがとうございます –

関連する問題