Jump to content

ACTION_IMAGE_CAPTURE et EXTRA_OUTPUT sur HTC Hero


Pierre87

Recommended Posts

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

Link to comment
Share on other sites

ç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();
               }
           }

Link to comment
Share on other sites

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);  
}

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...