Commit ca4e7ca5 authored by Kavindu Randika's avatar Kavindu Randika

bug fixing

parent fda9d09d
/build
\ No newline at end of file
build
\ No newline at end of file
......@@ -7,6 +7,7 @@ import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.media.MediaScannerConnection;
import android.net.Uri;
......@@ -17,6 +18,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.PathUtils;
import androidx.fragment.app.Fragment;
import android.os.Environment;
......@@ -278,7 +280,7 @@ public class CameraFragment extends Fragment {
RequestQueue requestQueue = Volley.newRequestQueue(getContext());
requestQueue.add(stringRequest);
}
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
......@@ -316,9 +318,9 @@ public class CameraFragment extends Fragment {
@Override
public void onClick(View v) {
// System.out.println("print");
String image = getStringImage(bitmapimg);
// String image = getStringImage(bitmapimg);
// System.out.println(image);
System.out.println(currentPhotoPath);
System.out.println("image path"+currentPhotoPath);
try {
uploadImage(currentPhotoPath);
} catch (InterruptedException e) {
......@@ -495,14 +497,20 @@ public class CameraFragment extends Fragment {
if(requestCode == GALLERY_REQUEST_CODE){
if(resultCode == Activity.RESULT_OK){
Uri contentUri = data.getData();
File file_temp = new File(contentUri.getPath());
String path = getRealPathFromURI(getContext(),contentUri);
System.out.println("1 file_path"+path);
currentPhotoPath = path;
try{
bitmapimg = MediaStore.Images.Media.getBitmap(getContext().getContentResolver(), contentUri);
}
catch(IOException fileNotFoundException){
System.out.println(fileNotFoundException.getMessage().toString());
}
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp +"."+getFileExt(contentUri);
Log.d("tag", "onActivityResult: Gallery Image Uri: " + imageFileName);
try {
uploadImage(contentUri.getPath());
} catch (InterruptedException | IOException e) {
e.printStackTrace();
}
selectedImage.setImageURI(contentUri);
}
......@@ -511,6 +519,23 @@ public class CameraFragment extends Fragment {
}
public String getRealPathFromURI(Context context, Uri contentUri) {
Cursor cursor = null;
try {
String[] proj = { MediaStore.Images.Media.DATA };
cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} finally {
if (cursor != null) {
cursor.close();
}
}
}
private String getFileExt(Uri contentUri) {
ContentResolver c = getContext().getContentResolver();
MimeTypeMap mime = MimeTypeMap.getSingleton();
......@@ -536,39 +561,7 @@ public class CameraFragment extends Fragment {
private void dispatchTakePictureIntent() throws IOException {
// String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
// String imageFileName = "JPEG_" + timeStamp + "_.jpg";
// File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
// String path = storageDir + "/CameraImages/example.jpg";
// currentPhotoPath = path;
// File file = new File(path);
// Uri outputFileUri = Uri.fromFile( file );
// Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
// intent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri );
// startActivityForResult( intent, CAMERA_REQUEST_CODE );
// startActivityForResult( intent, CAPTURE_IMAGE );
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePictureIntent, CAMERA_REQUEST_CODE);
// Ensure that there's a camera activity to handle the intent
// if (takePictureIntent.resolveActivity(getContext().getPackageManager()) != null) {
// // Create the File where the photo should go
// File photoFile = null;
// try {
// photoFile = createImageFile();
// } catch (IOException ex) {
//
// }
// // Continue only if the File was successfully created
// if (photoFile != null) {
// Uri photoURI = FileProvider.getUriForFile(getContext(),
// "com.project.skindn_disease_app.fileprovider",
// photoFile);
// takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
// startActivityForResult(takePictureIntent, CAMERA_REQUEST_CODE);
// }
// startActivityForResult(takePictureIntent, CAMERA_REQUEST_CODE);
// }
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment