从相机将照片保存到Android的内部存储 [英] save the photos from camera to android internal storage

查看:598
本文介绍了从相机将照片保存到Android的内部存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我成功地保存于Android相机中的照片
使用以下根路径

  Environment.getExternalStorageDirectory()

  context.getExternalFilesDir(空)

但我不能保存使用下面的根路径

  context.getFilesDir()

你知道是否可以从Android相机拍摄的照片保存到具有Android的内部存储 context.getFilesDir()的根文件夹?

我用下面的code键启动相机:

 意图takePictureIntent =新
             意图(MediaStore.ACTION_IM​​AGE_CAPTURE);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(picFile));
            startActivityForResult(takePictureIntent,REQUEST_TAKE_PICTURE);//这个code经常拿摄像机输出
 @覆盖
           公共无效的onActivityResult(INT申请code,INT结果code,
            意图数据){
        如果((要求code == REQUEST_TAKE_PICTURE)及及(结果code ==
            Activity.RESULT_OK)
                ){
            Toast.makeText(这一点,可以得到的形象。
             Toast.LENGTH_LONG).show();            //位图的照片=(位图)data.getExtras()获得(数据);          //的System.out.println(照片+ photo.getWidth());
//最后ImageView的ImageView的=(ImageView的)findViewById(R.id.imageView1);
// imageView.setImageBitmap(照片);
            }否则如果((要求code == REQUEST_TAKE_PICTURE)及及(结果code == Activity.RESULT_CANCELED)){                Toast.makeText(这一点,不能获得图像。Toast.LENGTH_LONG).show();
            }        }


解决方案

您不能使用 getFilesDir(),因为你正在推出一个第三方相机应用走图片,它无法写入您的应用程序的内部存储空间。

I successfully save the pictures from android camera to using the following root paths

Environment.getExternalStorageDirectory()

and

context.getExternalFilesDir(null)

but I cannot save using the following root path

context.getFilesDir()

Do you know if it is possible to save the pictures taken from android camera to the android internal storage which have context.getFilesDir() as root folder?

I use the following code to start the camera:

    Intent takePictureIntent = new  
             Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(picFile));
            startActivityForResult(takePictureIntent, REQUEST_TAKE_PICTURE);

//and this code I used to get the camera output


 @Override
           public void onActivityResult(int requestCode, int resultCode,
            Intent data) {
        if ((requestCode == REQUEST_TAKE_PICTURE) && (resultCode ==
            Activity.RESULT_OK)
                ) {
            Toast.makeText(this, "Can get the image.",   
             Toast.LENGTH_LONG).show();

            //Bitmap photo = (Bitmap) data.getExtras().get("data");     

          //  System.out.println("photo "+photo.getWidth());
//          final ImageView imageView = (ImageView) findViewById(R.id.imageView1);            
//            imageView.setImageBitmap(photo);        
            } else if ((requestCode == REQUEST_TAKE_PICTURE) && (resultCode == Activity.RESULT_CANCELED)) {

                Toast.makeText(this, "Cannot get the image.", Toast.LENGTH_LONG).show();
            } 

        }

解决方案

You cannot use getFilesDir(), because you are launching a third-party camera app to take the picture, and it cannot write to your app's internal storage.

这篇关于从相机将照片保存到Android的内部存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆