Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
755 views
in Technique[技术] by (71.8m points)

file - How to save images from Camera in Android to specific folder?

Basically, what I want to do is allow the user to make their own folder and then go to an activity that contains a button to launch the camera.

From there I want to be able to launch the camera and save the camera images into the newly created folder.

I am having trouble with last part of saving the camera images into the newly created folder.

Here is my Code :

 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button b = (Button) findViewById(R.id.button1);
    b.setOnClickListener(new OnClickListener() {


        EditText text = (EditText)findViewById(R.id.editText1); 
        EditText text2 = (EditText)findViewById(R.id.editText2);



        @Override
        public void onClick(View v) {

            final String name = text.getText().toString();
            final String placeName = text2.getText().toString(); 

            String place = placeName.substring(0,3);
            String direct = name + place ;

            File folder = new File("/sdcard/CameraTest/" + direct + "/");
            folder.mkdirs();

            Intent myIntent = new Intent(CameraTestActivity.this, Press.class);
            myIntent.putExtra("key", "/sdcard/CameraTest/" + direct + "/");
            startActivity(myIntent);

        }
    });

From here I transition into this activity:

public class Press extends Activity {


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.afterenter);
        final String direct = this.getIntent().getStringExtra("key");


        // TODO Auto-generated method stub
        Button p = (Button) findViewById(R.id.button2);
        p.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                Intent camera= new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

                startActivityForResult(camera, 1);

            }
        });



    Button np = (Button) findViewById(R.id.button3);
    np.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent next = new Intent(Press.this, CameraTestActivity.class);
            startActivity(next);
        }
    });         
    }
}

Please tell me how to save the images from the camera into the newly created folder.

I want the user to be able to take several pictures and then save these several pictures into that specific folder.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

add this code before calling camera activity,

Uri uriSavedImage=Uri.fromFile(new File("/sdcard/flashCropped.png"));
camera.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
startActivityForResult(camera, 1);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...