Android API等级8选取最后拍摄的照片表格特定文件夹

时间:2013-09-23 12:35:13

标签: java android file sftp

我想拍一张用我的应用程序获取的照片并通过SFTP发送。我将照片放到特定文件夹中:

timeStamp = new SimpleDateFormat("yyyyMMDD_HHmmss").format(new Date());

root = new File(Environment.getExternalStorageDirectory()+ File.separator + "OpenClinica" + File.separator);

root.mkdirs();

sdDir = new File(root, "OC_" + timeStamp + ".jpg");

现在我需要通过点击按钮拍摄这张照片并通过SFTP发送。

我有SFTP的类/方法,但我无法获取文件选择器。

感谢您的帮助

2 个答案:

答案 0 :(得分:0)

试试这段代码:

@Override
public void onClick(View v) {
    if (v.getId() == findViewById(R.id.ID).getId()){
         Intent intent = new Intent();
         intent.setType("image/*");
         intent.setAction(Intent.ACTION_GET_CONTENT);
         startActivityForResult(Intent.createChooser(intent, "Seleccionar vídeo"), PICK_IMAGE);          
    }

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(requestCode == PICK_IMAGE && data != null && data.getData() != null) {
        Uri _uri = data.getData();

        //User had pick an video.
        Cursor cursor = getContentResolver().query(_uri, new String[] { android.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null);
        cursor.moveToFirst();

        //Link to the video
        final String imageFilePath = cursor.getString(0);
        cursor.close();
    }
}

希望它有用!!

答案 1 :(得分:0)

非常感谢以这种方式解决:

protected void startCameraActivity() {
        outputFileUri = Uri.fromFile(sdDir);
        i = new Intent("android.media.action.IMAGE_CAPTURE");
        i.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        startActivityForResult(i, 0);
    }

    //Manage everything that happens after the Camera was started  
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
//      
        // Write the Captured Image as File
        Intent intent = new Intent();
        intent.putExtra("uri", sdDir.getPath());
        //Grab the Captured Image from the Cache an create the Preview
        bmp = BitmapFactory.decodeFile(outputFileUri.getPath());
        //Rotates the Preview Image
        Matrix matrix=new Matrix();
        matrix.postRotate(90);
        Bitmap bMapRotate = Bitmap.createBitmap(bmp, 0, 0,bmp.getWidth(),bmp.getHeight(), matrix, true);
        //Set the Rotated Image as Preview in the ImageView from the Layout
        iv.setImageBitmap(bMapRotate);
        setResult(0, intent);

    }