0

So im a little stuck with this. At first i used a simple intent to capture a photo and show that in a imageview using the bitmap it saves in extras. to save this so that i can upload it to firebase storage is proving difficult. ive followed the training lesson in android developer taking photos simply. ive looked around and think i might also need to scan with media score, but the actual photo is already found in gallery

i can get a file created but it is 0bytes in the gallery app i can actually see the photo taken but in file manager and desktop browser i can see only an empty file. I really dont want to have to use the camera api.

Also once i take the photo the using the intent the app taking the photo crashes and then continues my app. before file provider it would work and return a bitmap Thanks for looking.

Any code redundancy in createfilepath method is me experimenting with android i think the problem is with the camera apps crashing but with it happening to all the caera apps i have its my code

<?xml version="1.0" encoding="utf-8"?>
<resources>
<paths xmlns:android="http://schemas.android.com/apk/res/android"> 
<external-path name="my_images" path="Android/data/com.example.testing.app/files/Pictures" />

</paths>
</resources>


public void newImage(){
    if(pic.resolveActivity(getActivity().getPackageManager())!=null) {
        File photoFile = createFilePath();
        if(photoFile!=null){
            Log.d("abc", "newImage: "+photoFile.toString());

            Uri photoURI = FileProvider.getUriForFile(getActivity(),"com.example.testing.app.fileprovider",photoFile);
            Log.d("abc", "newImage: "+photoURI.toString());
            pic.putExtra(MediaStore.EXTRA_OUTPUT,photoURI);
            startActivityForResult(pic,1);
        }

    }
}

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Log.d("test", "onActivityResult: ");
    if(requestCode==1&&resultCode==RESULT_OK){
    //    galleryAddPic();
        Bundle extra= data.getExtras();
         bit =(Bitmap) extra.get("data");
        Log.d("abc", "onActivityResult: "+extra.get(MediaStore.EXTRA_OUTPUT).toString());
        picture.setImageBitmap(bit);
    }
}


 public File createFilePath(){
    File filepath= getActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES);
    Log.d(TAG, "createFilePath: "+ filepath.toString());
    File filepath2 = new File(filepath.getAbsolutePath());
    File filepath3=null;

    try {
         filepath3 = File.createTempFile("temp", ".jpg", filepath4);
        Log.d(TAG, "createFilePath: ");
        return filepath3;
  //      nCurrentPhotoPath = filepath3.getAbsolutePath();
    }catch(IOException e){
        e.printStackTrace();
        Log.d(TAG, "createFilePath: ");
    }

    return filepath3;
}

EDIT Provider in Manifest

 <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="com.example.testing.app.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/filepaths"/>

    </provider>

features and permissions

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>


<uses-feature android:name="android.hardware.Camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera2" android:required="false"/>
<uses-feature android:name="android.hardware.location.gps"/>
ah4444
  • 1
  • 3

2 Answers2

0

A workaround is to remove the file provider and take the bitmap returned from the intent and in onactivity use the code provided in this answer code

Community
  • 1
  • 1
ah4444
  • 1
  • 3
0

extra.get("data") is a thumbnail, your real image is in the file that you created photoFile

Oscar Duarte
  • 521
  • 5
  • 5