2017-03-01 139 views
1

我要救从cameraextSdcard捕获image,但问题的images储存在我的手机的internal memoryandroid 4.4.4(kitkat)android 5.1.1android 4.2图像已经存储在extsdcard,你有什么这个想法请吗?保存拍摄的图像,以SD卡

+0

由于Android 4.4你不能写二级/移动存储。 –

+0

https://commonsware.com/blog/2014/04/09/storage-situation-removable-storage.html – CommonsWare

+0

有没有解决方案!我想存储许多图片,内部存储器不是解决方案! – rheema

回答

0

根据Document

应用不得被允许写入第二外部存储 设备,除了在

可以编写到应用特定的文件夹上primary external storage即,它们的具体包/sdcard/Android/data/package/secondary external storage的应用程序特定文件夹即/extSdcard/Android/data/package/WRITE_EXTERNAL_STORAGE您可以写信给所有位置primary external storage/sdcard/ bu t您无法写入secondaryexternal storage(应用程序特定文件夹除外)上的任何位置。

+0

我试过这个,但它不工作! – rheema

0

所以我必须创建一个文件夹与我的应用程序包的名称,但在我的应用程序的代码中,我必须做一个更改或不?这是我的代码

Button captureButton = (Button) findViewById(R.id.button_capture); 
    captureButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 


         mCamera.takePicture(null, null, mPicture); 



} 

/** 
* Helper method to access the camera returns null if it cannot get the 
* camera or does not exist 
* 
* @return 
*/ 
private Camera getCameraInstance() { 
    Camera camera = null; 
    try { 
     camera = Camera.open(); 
    } catch (Exception e) { 
     // cannot get camera or does not exist 
    } 
    return camera; 
} 

PictureCallback mPicture = new PictureCallback() { 
    @Override 
    public void onPictureTaken(byte[] data, Camera camera) { 
     File pictureFile = getOutputMediaFile(); 

     if (pictureFile == null) { 
      return; 
     } 
     try { 
      pictureFile.createNewFile(); 
      FileOutputStream fos = new FileOutputStream(pictureFile); 
      fos.write(data); 
      fos.close(); 
     } catch (FileNotFoundException e) { 

     } catch (IOException e) { 
     } 
    } 

}; 

    private static File getOutputMediaFile() { 
     File mediaStorageDir = new File(Environment.getExternalStorageDirectory() + "/MyCameraApp/"); 
     if (!mediaStorageDir.exists()) { 
      mediaStorageDir.mkdir(); 
     } 
     return mediaStorageDir; 
    } 


@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 

    return true; 
} 


private String currentDateFormat(){ 
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HH_mm_ss"); 
    String currentTimeStamp = dateFormat.format(new Date()); 
    return currentTimeStamp; 
} 

}