0
I am creating an app where I have several camera calls, and I would like to create a class to call the camera to use in the project , well, the call from Activity is being made with the activityforresult in this class, the photo and captured, but when returning to the main Activity, onativityresult in catching the code
Main_activity
TirarFotoPrincipal(context, IV_Clicado, String_Dados);
Camera_class
public void TirarFotoPrincipal(final Context context, final ImageView imageView, final String Dados) { imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final String nome_foto = "foto_olho_" + lado_do_olho + "_" + id_animal_prontuario + "_principal.jpg"; final String imagem = Constante.LOCALPATH + nome_foto; String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/" + nome_foto; File Nova_Foto = new File(path); File file = new File(new File(Environment.getExternalStorageDirectory(), "myfolder"), nome_foto); String CAMERA_FP_AUTHORITY = "com.example.john.oftalmovet.fileprovider"; fileUri = FileProvider.getUriForFile( context, CAMERA_FP_AUTHORITY, Nova_Foto); Intent Intent_Camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Intent_Camera.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); Intent_Camera.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); startActivityForResult(Intent_Camera, codigo_for_result); } }); }
these two codes are working, but I’m having trouble adding onactivityresult,
I tried to put in camera class but n returned the data, also tried to put in main Activity but it did not work too
if I put the class camera code directly into main_activity and call onactivityresult with what I need to do after the photo capture, it works perfectly, but it will be written in several other
I appreciate the help!
You can capture the values you receive in
onActivityResult
and send to anotheractivity
?. Ex:Intent intent = new Intent(context, another.class); intent.putExtra("key", intentDoActivityResult.getExtras());
– Valdeir Psr
@Valdeirpsr then does not have a way to use the onactivityresult ? I will have to create another internet to do this?
– Jonnys J.
The
onActivityResult´ só funcionará na
Activityque você invocou o
startActivityForResult. O que seria essa classe "Camera" e porque será re-escrito em diversas outras
Activity`? If you can explain...– Valdeir Psr
@Valdeirpsr , the camera class will be opened in several different activities , but its results should go back to the Activity that calls the class, this way , I want to use this class for all and I will not need to redo the code in each Activity
– Jonnys J.
You called the
super.onActivityResult(..)
within yourMain_Activity
?– Danilo de Oliveira
@Danilodeoliveira did not do this on main_activity
– Jonnys J.
The question is very scrupulous, but let me get this straight, are you trying to re-use a camera opening code? If that’s it you can declare a class, extend it from an Activity of your preference, implement the method with public or protected modifier, and in your Main_activity extension of the Class you created, and the rest is just call this method, now to pick up the return, just rewrite onActivityResult, and if you remove the SUPER method from onActivityResouth your Fragments will not receive the results if you make startActivityForResult calls
– Weslley Barbosa