Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. public class MainActivity extends Activity {
  2.  
  3. Button button;
  4. ImageView imageView;
  5. static final int CAM_REQUEST = 1;
  6.  
  7. @Override
  8. protected void onCreate(Bundle savedInstanceState) {
  9. super.onCreate(savedInstanceState);
  10. setContentView(R.layout.activity_main);
  11. button = (Button) findViewById(R.id.CameraButton);
  12. imageView = (ImageView)findViewById(R.id.Image_view);
  13. button.setOnClickListener(new View.OnClickListener() {
  14.  
  15. @Override
  16. public void onClick(View v) {
  17. Intent camera_intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  18. File file = getfile();
  19. camera_intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
  20. startActivityForResult(camera_intent, CAM_REQUEST);
  21. }
  22. });
  23. }
  24.  
  25. private File getfile()
  26. {
  27.  
  28. File folder = new File("=sdcard/Camera_App");
  29.  
  30. if(!folder.exists()) //CHECKS FOR FOLDER
  31. {
  32. folder.mkdir(); //IF NO FOLDER IT CREATES FOLDER
  33. }
  34.  
  35. File image_file = new File(folder, "Image.jpg");
  36. return image_file;
  37. }
  38.  
  39. @Override
  40. protected void onActivityResult (int requestCode, int resultCode, Intent data) {
  41. String path = "sdcard/Camera_App/Image.jpg";
  42. imageView.setImageDrawable(Drawable.createFromPath(path));
  43.  
  44. }
  45.  
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement