Advertisement
Guest User

cameraActivity

a guest
May 26th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. package com.eksell.eksell.eksell;
  2.  
  3. import android.content.Intent;
  4. import android.graphics.Bitmap;
  5. import android.net.Uri;
  6. import android.provider.MediaStore;
  7. import android.support.v7.app.AppCompatActivity;
  8. import android.os.Bundle;
  9. import android.widget.ImageView;
  10. import android.widget.Toast;
  11.  
  12.  
  13.  
  14. public class CameraActivity extends AppCompatActivity {
  15. private static final int REQUEST_IMAGE_CAPTURE = 1;
  16.  
  17.  
  18.  
  19. @Override
  20. protected void onCreate(Bundle savedInstanceState) {
  21. super.onCreate(savedInstanceState);
  22.  
  23. setContentView(R.layout.activity_camera);
  24.  
  25. Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  26.  
  27. takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
  28.  
  29. startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
  30.  
  31. }
  32.  
  33. @Override
  34. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  35. if (requestCode == REQUEST_IMAGE_CAPTURE) {
  36. if (resultCode == RESULT_OK) {
  37. Bitmap photo = (Bitmap)data.getExtras().get("data");
  38. Bundle extras = data.getExtras();
  39. Bitmap imageBitmap = (Bitmap) extras.get("data");
  40. ImageView.setImageBitmap(imageBitmap);
  41.  
  42. Intent intent = new Intent(this, SendActivity.class);
  43. intent.putExtra("NewImage", photo);
  44.  
  45. startActivity(intent);
  46.  
  47. finish();
  48. }
  49. else if (resultCode == RESULT_CANCELED) {
  50. Toast.makeText(this, "Image capture canceled", Toast.LENGTH_LONG).show();
  51. finish();
  52. } else {
  53. Toast.makeText(this, "Image capture failed", Toast.LENGTH_LONG).show();
  54. finish();
  55. }
  56. }
  57. }
  58. =
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement