Commit ca4e7ca5 authored by Kavindu Randika's avatar Kavindu Randika

bug fixing

parent fda9d09d
/build build
\ No newline at end of file \ No newline at end of file
...@@ -7,6 +7,7 @@ import android.content.ContentValues; ...@@ -7,6 +7,7 @@ import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.media.MediaScannerConnection; import android.media.MediaScannerConnection;
import android.net.Uri; import android.net.Uri;
...@@ -17,6 +18,7 @@ import androidx.annotation.NonNull; ...@@ -17,6 +18,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.core.graphics.PathUtils;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import android.os.Environment; import android.os.Environment;
...@@ -247,38 +249,38 @@ public class CameraFragment extends Fragment { ...@@ -247,38 +249,38 @@ public class CameraFragment extends Fragment {
System.out.println(jsonObject); System.out.println(jsonObject);
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
},new Response.ErrorListener() { },new Response.ErrorListener() {
@Override @Override
public void onErrorResponse(VolleyError error) { public void onErrorResponse(VolleyError error) {
Toast.makeText(getContext(), "No internet connection", Toast.LENGTH_LONG).show(); Toast.makeText(getContext(), "No internet connection", Toast.LENGTH_LONG).show();
System.out.println("error"); System.out.println("error");
System.out.println(error.toString()); System.out.println(error.toString());
System.out.println("error"); System.out.println("error");
} }
}) })
{ {
protected Map<String, String> getParams() { protected Map<String, String> getParams() {
Map<String, String> params = new Hashtable<>(); Map<String, String> params = new Hashtable<>();
params.put("req_file", image); params.put("req_file", image);
return params; return params;
} }
}; };
{ {
int socketTimeout = 30000; int socketTimeout = 30000;
stringRequest.setRetryPolicy(new DefaultRetryPolicy( stringRequest.setRetryPolicy(new DefaultRetryPolicy(
5000, 5000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
// RetryPolicy policy = new DefaultRetryPolicy(socketTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT); // RetryPolicy policy = new DefaultRetryPolicy(socketTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
// stringRequest.setRetryPolicy(policy); // stringRequest.setRetryPolicy(policy);
RequestQueue requestQueue = Volley.newRequestQueue(getContext()); RequestQueue requestQueue = Volley.newRequestQueue(getContext());
requestQueue.add(stringRequest); requestQueue.add(stringRequest);
}
} }
}
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
...@@ -316,9 +318,9 @@ public class CameraFragment extends Fragment { ...@@ -316,9 +318,9 @@ public class CameraFragment extends Fragment {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
// System.out.println("print"); // System.out.println("print");
String image = getStringImage(bitmapimg); // String image = getStringImage(bitmapimg);
// System.out.println(image); // System.out.println(image);
System.out.println(currentPhotoPath); System.out.println("image path"+currentPhotoPath);
try { try {
uploadImage(currentPhotoPath); uploadImage(currentPhotoPath);
} catch (InterruptedException e) { } catch (InterruptedException e) {
...@@ -495,14 +497,20 @@ public class CameraFragment extends Fragment { ...@@ -495,14 +497,20 @@ public class CameraFragment extends Fragment {
if(requestCode == GALLERY_REQUEST_CODE){ if(requestCode == GALLERY_REQUEST_CODE){
if(resultCode == Activity.RESULT_OK){ if(resultCode == Activity.RESULT_OK){
Uri contentUri = data.getData(); 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 timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp +"."+getFileExt(contentUri); String imageFileName = "JPEG_" + timeStamp +"."+getFileExt(contentUri);
Log.d("tag", "onActivityResult: Gallery Image Uri: " + imageFileName); Log.d("tag", "onActivityResult: Gallery Image Uri: " + imageFileName);
try {
uploadImage(contentUri.getPath());
} catch (InterruptedException | IOException e) {
e.printStackTrace();
}
selectedImage.setImageURI(contentUri); selectedImage.setImageURI(contentUri);
} }
...@@ -511,6 +519,23 @@ public class CameraFragment extends Fragment { ...@@ -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) { private String getFileExt(Uri contentUri) {
ContentResolver c = getContext().getContentResolver(); ContentResolver c = getContext().getContentResolver();
MimeTypeMap mime = MimeTypeMap.getSingleton(); MimeTypeMap mime = MimeTypeMap.getSingleton();
...@@ -536,39 +561,7 @@ public class CameraFragment extends Fragment { ...@@ -536,39 +561,7 @@ public class CameraFragment extends Fragment {
private void dispatchTakePictureIntent() throws IOException { 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); Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePictureIntent, CAMERA_REQUEST_CODE); 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