2

我想用我的应用程序拍摄一张照片并通过 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 的类/方法,但我无法获取文件选择器。

感谢您的帮助

4

2 回答 2

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

希望有用!!

于 2013-09-24T19:01:39.143 回答
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);

    }
于 2013-09-27T10:01:10.970 回答