J'ai suivi Google's guide Receiving Simple Data from Other Apps et j'ai réussi à obtenir l'URI comme promis, mon icône de l'application est affichée lorsqu'une image doit être partagée.Les données d'image simples reçues d'autres applications ont une résolution inférieure ou égale à 0
Pourtant, il y a un problème spécifique, voici comment il va:
if (Intent.ACTION_SEND.equals(action) && type != null) {
if (type.startsWith("image/")) {
handleSendImage(intent); // Handle single image being sent
}
}
handleSendImage(intent);
conduit à
void handleSendImage(Intent intent) {
Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (imageUri != null) {
pfadPhoto = getRealPathFromURI_API19(this, imageUri);
i("handleSendImage "+pfadPhoto);
fBildVerkleinern(pfadPhoto);
}
}
public String getRealPathFromURI_API19(Context context, Uri uri){
String result;
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
if (cursor == null) { // Source is Dropbox or other similar local file path
result = uri.getPath();
} else {
cursor.moveToFirst();
int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
result = cursor.getString(idx);
cursor.close();
}
return result;
}
fBildVerkleinern(pfadPhoto);
conduit à
private void fBildVerkleinern(String bildpfad) {
...
iv = (ImageView)findViewById(R.id.mImageView);
int ivBreite = iv.getWidth();
int ivHoehe = iv.getHeight();
...
v = BitmapFactory.decodeFile(bildpfad); //bildpfad = pfadPhoto
...
bitmap2 = getResizedBitmap(v,(int)((float)ivBreite/vergroesserungsFaktor),ivBreite);
...
}
getResizedBitmap
conduit à
public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
if (bm != null) {
int width = bm.getWidth();
int height = bm.getHeight();
float scaleWidth = ((float) newWidth)/width;
float scaleHeight = ((float) newHeight)/height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
return resizedBitmap;
}
return null;
}
et Bitmap.createBitmap
conduit à
Caused by: java.lang.IllegalArgumentException: width and height must be > 0
Pourtant, j'ai aussi un onActivityResult
qui est exécuté après une sélection d'image a lieu avec le gestionnaire de fichiers qui ressemble à
if (requestCode == CHOOSE_PHOTO) {
if (data == null) {
f("Fehler");
return;
}
pfadPhoto = getRealPathFromURI_API19(this, data.getData());
fBildVerkleinern(pfadPhoto);
...
}
et cela fonctionne sans problème.
Où voyez-vous l'erreur?