Android Studio Image to Upload Not Changing

I want to upload epitome from gallery in my android app. When I click on button, the gallery should exist opened. After selecting image, I desire to open another action named UploadActivity. There the thumbnail of the paradigm should exist previewed. The Upload Button will below the thumbnail.

Upload Image From Gallery

Simply when I Cull photo from gallery, then the thumbnail of the prototype are not previewing. I am unable to upload the photo also. My Code goes hither: (Scan.Coffee)

                      private static final int CAMERA_CAPTURE_IMAGE_REQUEST_CODE = 100; public static final int MEDIA_TYPE_IMAGE = 1; private static final int SELECT_IMAGE = 2; private Uri fileUri; // file url to store epitome/video ImageView dummy; individual Push button btnCapturePicture; private Button btnGallery;  @Override protected void onCreate(Package savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.scan);     dummy = (ImageView) findViewById(R.id.dummyphoto);     btnCapturePicture = (Button) findViewById(R.id.btnCapturePicture);     btnGallery = (Button) findViewById(R.id.btnGallery);     /**      * Capture epitome button click outcome      */     btnCapturePicture.setOnClickListener(new View.OnClickListener() {          @Override         public void onClick(View v) {             // capture picture show             captureImage();         }     });      btnGallery.setOnClickListener(new View.OnClickListener(){          @Override         public void onClick(View v){             openGallery();         }      });      // Checking photographic camera availability     if (!isDeviceSupportCamera()) {         Toast.makeText(getApplicationContext(),                 "Sorry! Your device doesn't support camera",                 Toast.LENGTH_LONG).show();         // volition close the app if the device does't have camera         finish();     } }  /**  * Checking device has camera hardware or not  * */ private boolean isDeviceSupportCamera() {     if (getApplicationContext().getPackageManager().hasSystemFeature(             PackageManager.FEATURE_CAMERA)) {         // this device has a camera         render true;     } else {         // no camera on this device         return false;     } }  /**  * Launching photographic camera app to capture image  */ individual void captureImage() {     Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);      fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);      intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);      // start the image capture Intent     startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE); }  /**  * Launching Gallery to Choose Image  */ private void openGallery(){     Intent intent = new Intent();     intent.setType("paradigm/*");     intent.setAction(Intent.ACTION_GET_CONTENT);     fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);     intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);     startActivityForResult(Intent.createChooser(intent, "Select Image"),SELECT_IMAGE); }  /**  * Here we store the file url as information technology will be zero after returning from camera  * app  */ @Override protected void onSaveInstanceState(Bundle outState) {     super.onSaveInstanceState(outState);      // relieve file url in packet as information technology will be cypher on screen orientation     // changes     outState.putParcelable("file_uri", fileUri); }  @Override protected void onRestoreInstanceState(Bundle savedInstanceState) {     super.onRestoreInstanceState(savedInstanceState);      // become the file url     fileUri = savedInstanceState.getParcelable("file_uri"); }    /**  * Receiving activity event method volition be called after closing the camera  * */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {     // if the result is capturing Image     if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE) {         if (resultCode == RESULT_OK) {              // successfully captured the paradigm             // launching upload action             launchUploadActivity(true);           } else if (resultCode == RESULT_CANCELED) {              // user cancelled Image capture             Toast.makeText(getApplicationContext(),                     "User cancelled image capture", Toast.LENGTH_SHORT)                     .show();          } else {             // failed to capture paradigm             Toast.makeText(getApplicationContext(),                     "Sorry! Failed to capture image", Toast.LENGTH_SHORT)                     .show();         }      }      else if (requestCode == SELECT_IMAGE)     {         if (resultCode == Activeness.RESULT_OK)         {             if (data != cypher)             {                     launchUploadActivity(true);             }         } else if (resultCode == Activity.RESULT_CANCELED)         {             Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show();         }     }  }  private void launchUploadActivity(boolean isImage){     Intent i = new Intent(Browse.this, UploadActivity.course);     i.putExtra("filePath", fileUri.getPath());     i.putExtra("isImage", isImage);     startActivity(i); }                  

UploadActivity.Java Lawmaking goes hither:

          private ProgressBar progressBar; private String filePath = null; private TextView txtPercentage; private ImageView imgPreview; private Push btnUpload; long totalSize = 0;  @Override protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.activity_upload);     txtPercentage = (TextView) findViewById(R.id.txtPercentage);     btnUpload = (Button) findViewById(R.id.btnUpload);     progressBar = (ProgressBar) findViewById(R.id.progressBar);     imgPreview = (ImageView) findViewById(R.id.imgPreview);      // Receiving the data from previous activity     Intent i = getIntent();      // epitome path that is captured in previous activity     filePath = i.getStringExtra("filePath");      // boolean flag to place the media type, image     boolean isImage = i.getBooleanExtra("isImage", true);      if (filePath != null) {         // Displaying the paradigm on the screen         previewMedia(isImage);     } else {         Toast.makeText(getApplicationContext(),                 "Pitiful, file path is missing!", Toast.LENGTH_LONG).show();     }      btnUpload.setOnClickListener(new View.OnClickListener() {          @Override         public void onClick(View five) {             // uploading the file to server             new UploadFileToServer().execute();         }     });  }  /**  * Displaying captured epitome on the screen  * */ private void previewMedia(boolean isImage) {     // Checking whether captured media is image     if (isImage) {         imgPreview.setVisibility(View.VISIBLE);         // bimatp manufactory         BitmapFactory.Options options = new BitmapFactory.Options();          // downwardly sizing paradigm as it throws OutOfMemory Exception for larger         // images         options.inSampleSize = 8;          concluding Bitmap bitmap = BitmapFactory.decodeFile(filePath, options);          imgPreview.setImageBitmap(bitmap);     } else {         imgPreview.setVisibility(View.GONE);     } }  /**  * Uploading the file to server  * */ private class UploadFileToServer extends AsyncTask<Void, Integer, String> {     @Override     protected void onPreExecute() {         // setting progress bar to cipher         progressBar.setProgress(0);         super.onPreExecute();     }      @Override     protected void onProgressUpdate(Integer... progress) {         // Making progress bar visible         progressBar.setVisibility(View.VISIBLE);          // updating progress bar value         progressBar.setProgress(progress[0]);          // updating pct value         txtPercentage.setText(Cord.valueOf(progress[0]) + "%");     }      @Override     protected String doInBackground(Void... params) {         return uploadFile();     }      @SuppressWarnings("deprecation")     private String uploadFile() {         String responseString = null;          HttpClient httpclient = new DefaultHttpClient();         HttpPost httppost = new HttpPost(Config.FILE_UPLOAD_URL);          try {             AndroidMultiPartEntity entity = new AndroidMultiPartEntity(                     new ProgressListener() {                          @Override                         public void transferred(long num) {                             publishProgress((int) ((num / (float) totalSize) * 100));                         }                     });              File sourceFile = new File(filePath);              // Adding file data to http torso             entity.addPart("epitome", new FileBody(sourceFile));                  

Here is Logcat:

          Eastward/MainActivity: Response from server: java.io.FileNotFoundException: /mnt/sdcard/Pictures/main/IMG_20170127_152930.jpg: open failed: ENOENT (No such file or directory)                  

doanefeliked1955.blogspot.com

Source: https://stackoverflow.com/questions/41899389/cannot-upload-image-from-gallery-in-android-studio

0 Response to "Android Studio Image to Upload Not Changing"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel