Vector
Vector

Reputation: 3235

manually save jpg to emulator

We are dealing with the code from a course that loads an image. We are trying to do this with an Emulator API 26 Play Store active We have no jpg pictures on the emulator. The Device File Explore will let us Upload a jpg. We have tried various folders with no luck. Our question is where to Upload the jpg to in the Device File Explore? Code is Kotlin and the upload method is posted below

    fun onChooseImage(view:View){
    val intent = Intent()
    intent.type = "image/*"
    intent.action = Intent.ACTION_GET_CONTENT

    val chooser = Intent.createChooser(intent,"Choose Image for Habit")
    startActivityForResult(chooser,CHOOSE_IMAGE_REQUEST)

    Log .d(TAG,"Image was sent" )
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)

    if(requestCode == CHOOSE_IMAGE_REQUEST && resultCode == Activity.RESULT_OK
    && data != null && data.data != null){
        Log.d(TAG,"An Image WAS Choosen")

        val bitmap = tryReadBitmap(data.data)
        bitmap?.let {
            ivIcon.setImageBitmap(bitmap)
            Log.d(TAG,"We Updated and Read Bitmap")
        }
    }
}

private fun tryReadBitmap(data: Uri?): Bitmap?{
    return try{
        MediaStore.Images.Media.getBitmap(contentResolver,data)
    }catch (e:IOException){
        e.printStackTrace()
        null
    }
}

And we are using Cold Boot on the emulator. We have looked at other posts that suggest you can not use the emulator camera to save pictures to the emulator. Does this mean we need a real device to test this code?

Upvotes: 0

Views: 74

Answers (2)

James_Duh
James_Duh

Reputation: 1371

Grendel's answer is workable but I would like to provide a less intensive set of steps
1. Load the app in question
2. Open AVD manager and select the little down icon next to the Emulator your using
3. Click on Wipe Data (suggestion keep Emulator setting Quick Boot) <- other topic
4. Store your jpg in this path Storage->Self->Primary-DCIM
5. This is done by RIGHT click DCIM select Upload navigate to jpg
6. Close AVD manage
7. Run your app and select the same Emulator

Upvotes: 1

Vector
Vector

Reputation: 3235

It seems with the emulator you need to scan the emulator with Dev Tools BUT one other issue seems to pop up the cache for google play services and google play store needs to be cleared. In the processes of fixing this we tried so many fixes not sure of all the steps in order. As for where to upload the jpg that we are sure of use this path with /mnt/sdcard/DCIM/water.jpg When you get to DCIM right click it and select Upload

Here is a link that may help HELP LINK

Upvotes: 1

Related Questions