Pierre87 Posté(e) 8 mai 2010 Posté(e) 8 mai 2010 J'essaye de prendre une photo depuis mon application en faisant appel à l'application du téléphone. appel Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); PICTURE_DIRECTORY.mkdirs(); this.file = new File(PICTURE_DIRECTORY, System.currentTimeMillis() + ".jpg"); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(this.file)); this.startActivityForResult(intent, 0); activity result if (resultCode == RESULT_OK) { try { Bitmap bm = BitmapFactory.decodeFile(this.file.getCanonicalPath()); if (bm == null) { Bundle bundle = data.getExtras(); if (bundle != null) { Object o = bundle.get("data"); if (o != null && o instanceof Bitmap) { bm = (Bitmap) o; } } } this.setBitmap(bm); } catch (IOException e) { e.printStackTrace(); } } ça marche parfaitement sur mon nexus one mais sur le Hero, il ne prend pas en compte le paramètre EXTRA_OUTPUT Donc la photo est enregistrée dans le dossier par défaut du Hero :( Et je ne peux pas la récupérer :P
Pierre87 Posté(e) 8 mai 2010 Auteur Posté(e) 8 mai 2010 ça a l'air de marcher ça ... c'est quoi la bonne méthode ? if (resultCode == RESULT_OK) { try { Bitmap bm = BitmapFactory.decodeFile(this.file.getCanonicalPath()); if (bm == null) { Uri uri = data.getData(); if (uri != null) { bm = BitmapFactory.decodeStream(this.getContentResolver().openInputStream(uri)); } } if (bm == null) { Bundle bundle = data.getExtras(); if (bundle != null) { Object o = bundle.get("data"); if (o != null && o instanceof Bitmap) { bm = (Bitmap) o; } } } this.setBitmap(bm); } catch (IOException e) { e.printStackTrace(); } }
Invité Posté(e) 8 mai 2010 Posté(e) 8 mai 2010 Donc la photo est enregistrée dans le dossier par défaut du Hero :( Et je ne peux pas la récupérer :P Je pense que tu peux y avoir acces comme ça: public void lastPhoto() { String [] proj={MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Media.TITLE, MediaStore.Images.Media.DATE_TAKEN}; Cursor cursor = managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj, // Which columns to return null, null, // WHERE clause selection arguments (none) null); // Order-by clause (ascending by name) int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME); cursor.moveToLast(); // Little image cursor.moveToPrevious(); // Big image filename = cursor.getString(column_index); //return cursor.getString(column_index); }
Pierre87 Posté(e) 8 mai 2010 Auteur Posté(e) 8 mai 2010 en fait j'ai trouvé la solution :P il faut regarder successivement à 3 endroits : - au fichier dont on a passé l'uri à l'intent (ne marche pas sur le hero) - faire un getData() sur l'intent reçu (on récupère une uri) - récupérer l'image fournie dans le bundle de l'intent (faible résolution)
Recommended Posts
Archivé
Ce sujet est désormais archivé et ne peut plus recevoir de nouvelles réponses.