In Android Studio choose New Project β Empty Views Activity, with Language Java and Minimum SDK API 24.
2. Design the screen
In activity_main.xml, add a rounded card holding an ImageView (with a "Your photo will appear here" hint), a Take photo button and a Share button that starts disabled.
3. Give the camera somewhere to save
The camera app can't write into your app's private files directly. A FileProvider gives it a safe content:// address for one file:
Create res/xml/provider_paths.xml, allowing the images/ folder in your cache.
Register the FileProvider inside <application> in the manifest, with the authority ${applicationId}.provider.
4. Ask for a full-size photo
Register ActivityResultContracts.TakePicture(). When you launch it with your FileProvider address, the camera saves the full-resolution photo straight into your file. The callback gets true if a photo was taken and false if the user backed out.
5. Show the photo
In the callback, call imageView.setImageURI(photoUri), hide the hint and enable Share.
6. Share it
Send an ACTION_SEND intent with the photo as EXTRA_STREAM, and add FLAG_GRANT_READ_URI_PERMISSION so the chosen app can read it.
7. Run it
Run on a phone, tap Take photo, snap a picture, then Share it to any app. Most emulators also have a virtual camera.
If something goes wrong
Crash with "Failed to find configured root": the folder in provider_paths.xml must match the folder you create in code (images/).
The photo doesn't change on the second try: set the image to null first. The address stays the same, so the ImageView thinks nothing changed.
"No camera app found": the emulator or device has no camera app installed.
What's improved over the video
The video showed the small thumbnail the camera returns; this saves the full-resolution photo. Backing out no longer crashes the app, and you can share the photo.
Files affected
Check what to add and what to replace before copying code.
Opens the camera app, shows the full photo, and shares it.
MainActivity.java
packagecom.example.cameraapp;importandroid.content.ActivityNotFoundException;importandroid.content.Intent;importandroid.net.Uri;importandroid.os.Bundle;importandroid.view.View;importandroid.widget.Button;importandroid.widget.ImageView;importandroid.widget.TextView;importandroid.widget.Toast;importandroidx.activity.EdgeToEdge;importandroidx.activity.result.ActivityResultLauncher;importandroidx.activity.result.contract.ActivityResultContracts;importandroidx.appcompat.app.AppCompatActivity;importandroidx.core.content.FileProvider;importandroidx.core.graphics.Insets;importandroidx.core.view.ViewCompat;importandroidx.core.view.WindowInsetsCompat;importjava.io.File;/**
* Takes a full-resolution photo with the phone's camera app, shows it, and shares it.
* The camera app writes straight into a file we own, shared safely through FileProvider.
*/publicclassMainActivityextendsAppCompatActivity{Button btnpicture, btnShare;ImageView imageView;TextView placeholder;privateUri photoUri;// TakePicture saves the full photo to photoUri and reports true when a photo was taken.privatefinalActivityResultLauncher<Uri> takePicture =registerForActivityResult(newActivityResultContracts.TakePicture(), saved ->{if(saved){
imageView.setImageURI(null);// forget the previous photo at the same address
imageView.setImageURI(photoUri);
placeholder.setVisibility(View.GONE);
btnShare.setEnabled(true);}else{Toast.makeText(this,R.string.cancelled,Toast.LENGTH_SHORT).show();}});@OverrideprotectedvoidonCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);EdgeToEdge.enable(this);setContentView(R.layout.activity_main);ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main),(v, insets)->{Insets bars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(bars.left, bars.top, bars.right, bars.bottom);return insets;});
btnpicture =findViewById(R.id.btncamera_id);
btnShare =findViewById(R.id.btnshare_id);
imageView =findViewById(R.id.image);
placeholder =findViewById(R.id.placeholder);
photoUri =newPhotoUri();
btnpicture.setOnClickListener(v ->{try{
takePicture.launch(photoUri);}catch(ActivityNotFoundException e){Toast.makeText(this,R.string.no_camera,Toast.LENGTH_SHORT).show();}});
btnShare.setOnClickListener(v ->sharePhoto());}/** A file in our private cache, plus a content:// address the camera app is allowed to write to. */privateUrinewPhotoUri(){File folder =newFile(getCacheDir(),"images");//noinspection ResultOfMethodCallIgnored
folder.mkdirs();File file =newFile(folder,"captured_image.jpg");returnFileProvider.getUriForFile(this,getPackageName()+".provider", file);}privatevoidsharePhoto(){Intent share =newIntent(Intent.ACTION_SEND).setType("image/jpeg").putExtra(Intent.EXTRA_STREAM, photoUri).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);startActivity(Intent.createChooser(share,getString(R.string.share_with)));}}