0

これは、インテントを作成するために使用するコードです:

try {
                    file = createImageFile();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                 if(file!= null)
                 {

                    Log.d(Tag,"absolute path: "+imageAbsolutePath);
                    Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                    i.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(file));        
                    startActivityForResult(i, TAKE_PICTURE);
                 }

そして、これはカスタムの名前と場所でファイルを返すメソッドです:

private File createImageFile() throws IOException {

      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
      String currentDate = sdf.format(new Date());

      SimpleDateFormat sdf2 = new SimpleDateFormat("HH:mm:ss");
      String currentTime = sdf2.format(new Date());
      String timeArray[] = currentTime.split(":");

      String imageName = currentDate+" "+timeArray[0]+"-"+timeArray[1]+"-"+timeArray[2];

   // create a File object for the parent directory
   File Pictures = new File(Environment.getExternalStorageDirectory()+File.separator+"Pictures");
   // have the object build the directory structure, if needed.
   if (!Pictures.exists()) {
       Pictures.mkdirs();
       Log.d(Tag,"Pictures folder created: "+Pictures);
       }else
       {
           Log.d(Tag,"Pictures folder Already Exists: "+Pictures);
       }

       // File image = File.createTempFile(imageName,".jpg",Pictures);
   File image = new File (Pictures,imageName+".jpg" );
        Log.d(Tag,"This is Image name: "+ imageName);
        imageAbsolutePath = image.getAbsolutePath();

        return image;

    }

そして、これは私が使用する私の inActivityResult メソッドです:

case TAKE_PICTURE:
             if(resultCode == RESULT_OK)
                {
                 galleryAddPic();
                    Bitmap imgBitmap=null;

                    try
                        {
                        imgBitmap = lessResolution(imageAbsolutePath);                                             

                        }catch (Exception e)                             
                        {
                            e.printStackTrace();
                        }
                        if (imgBitmap!=null)
                        {
                            images.add(imgBitmap);
GridView grid = (GridView) findViewById(R.id.grid_view);
grid.setAdapter(new ImageAdapter(this));
}

この方法はすべて、Motorola Xoom、Motorola Droid、Razor、一部の Samsung デバイスなどのデバイスで機能しますが、たとえば、Samsung Galaxy Ace s5830m (Android 2.3.6) では機能しません。画像は正しく取得されますが、onActivityResult に戻っても何も起こりません。いくつかのテストの後、画像は DCIM/Camera フォルダーに保存され、Pictures フォルダーには保存されないため、何も表示されないことがわかりました。

4

1 に答える 1

0

一部の電話では機能していて、他の電話では機能していないという同じ問題がありました。このリンクで解決策を見つけました。これがお役に立てば幸いです。

カメラインテント写真の撮影後にギャラリー画像を削除する

于 2013-10-25T16:18:19.550 に答える