Home > Net >  Where Can I find activity of fragment?
Where Can I find activity of fragment?

Time:02-24

I have to write this function about webview fragment

private fun dispatchTakePictureIntent() {
Intent(MediaStore.ACTION_IMAGE_CAPTURE).also { takePictureIntent ->
    // Ensure that there's a camera activity to handle the intent
    takePictureIntent.resolveActivity(packageManager)?.also {
        // Create the File where the photo should go
         photoFile: File? = try {
            createImageFile()
        } catch (ex: IOException) {
            // Error occurred while creating the File
            Log.d("ERROR", "An error occured")
            null
        }
        // Continue only if the File was successfully created
        photoFile?.also {
            val photoURI: Uri = FileProvider.getUriForFile(
                    this,
                    "pim.android.photoapp.fileprovider",
                    it
            )
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI)
            startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE)
        }
    }
}

I am begginer, people wirte it in MainActivity, but what if app has a lot of fragments? where should i put it?

CodePudding user response:

use getActivity.packageManager in fragment

CodePudding user response:

then I got error Fragment not attached to an activity.

  • Related