The image storage location after shooting with the camera seems to be different for each camera application provided by a third vendor, so it is necessary to pay attention to the behavior and contents of the implicit * Intent * parameter. In addition, * Android * version 6.0 or later will require the user to check the authority and confirm the authorization when the app is started for the first time.
In this application, after taking an image of the gallery in the * Android * terminal or taking a picture with the camera, the image image is pasted after the screen transition.
When you touch the screen selection button in the * Intent * registration of the two functions (implicit * Intent * (gallery function) / implicit * Intent * (camera function)) of the gallery image or camera shooting in the * Android * terminal. Only implicit * Intent * (gallery function) is not displayed. Implicit * Intent * (camera function) is not displayed. On the other hand, if you cancel immediately and touch the screen selection button again, multiple implicit * Intent * (gallery function) will be displayed.
There was an error in the order of * Intent * registration of the two functions of * Android * gallery image or camera shooting in the terminal.
Implicit Intent (gallery function / camera function) registration order
// .....Abbreviation
private fun addPhoto(requestCode: Int) {
getCameraIntent()
createChooserIntent()
// .....Abbreviation
}
// .....Abbreviation
Creating an implicit Intent (camera function)
// .....Abbreviation
private fun getCameraIntent() {
Intent(MediaStore.ACTION_IMAGE_CAPTURE)
// .....Abbreviation
}
// .....Abbreviation
Implicit Intent (Gallery function) & Chooser creation
// .....Abbreviation
private fun createChooserIntent(): Intent {
Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = "image/*"
}
return Intent.createChooser(argument).apply {
putExtra(Intent.EXTRA_INITIAL_INTENTS,argument)
}
}
// .....Abbreviation
In this application, after touching the screen selection button to exclude the gallery image or the camera application provided by the third vendor and perform camera shooting, the image image is pasted after the screen transition.
Since the storage location of the captured image is unknown for the camera application provided by the third vendor, it is excluded from * Chooser * in consideration of the degree of influence.
None
After creating an implicit * Intent * (camera function), a new implicit * Intent * (camera function) is created if it matches the class name of the built-in camera function.
Exclude other camera apps
// .....Abbreviation
Intent(MediaStore.ACTION_IMAGE_CAPTURE).apply {
val intentInfoList = context?.packageManager?.queryIntentActivities(this, 0) ?: return
//Since the specifications of other camera apps are unknown, only the built-in camera is targeted.
for (intentInfo in intentInfoList) {
val packageName = intentInfo.activityInfo.packageName
val name = intentInfo.activityInfo.name
if (name.contains(CAMERA_CLS_NAME)) { // CAMERA_CLS_NAME → "com.android.camera"
Intent(MediaStore.ACTION_IMAGE_CAPTURE).apply {
// .....Abbreviation
}
}
}
}
// .....Abbreviation
In this application, after touching the screen selection button to take a picture of the gallery or the camera, the image image is pasted after the screen transition.
After touching the image selection button to take an image in the gallery or taking a picture with the camera, the image image is not displayed in * ImageView * on the screen transition destination layout, and the screen becomes blank.
When creating an implicit * Intent * (camera function) with * IntentChooser *, the * Intent * parameter of * onActivityResult () * will be * null * unless * putExtra (MediaStore.EXTRA_OUTPUT, cameraUri) * is excluded. , * Intent * Cannot get * Uri * taken by the camera. (Use the implicit * Intent * example from the official documentation)
Create an implicit * Intent * (camera function) by excluding * putExtra (MediaStore.EXTRA_OUTPUT, cameraUri) *.
putExtra()Exclusion
// .....Abbreviation
Intent(MediaStore.ACTION_IMAGE_CAPTURE).apply {
val intentInfoList = context?.packageManager?.queryIntentActivities(this, 0) ?: return
//Since the specifications of other camera apps are unknown, only the built-in camera is targeted.
for (intentInfo in intentInfoList) {
val packageName = intentInfo.activityInfo.packageName
val name = intentInfo.activityInfo.name
if (name.contains(CAMERA_CLS_NAME)) { // CAMERA_CLS_NAME → "com.android.camera"
Intent(MediaStore.ACTION_IMAGE_CAPTURE).apply {
// .....Abbreviation
// putExtra(MediaStore.EXTRA_OUTPUT, cameraUri)→ Exclusion
}
}
}
}
// .....Abbreviation
Technical causes and countermeasures for the first Android app & Kotlin addiction 1. Android screen transition (fragment) processing 3. Processing related to Android images
Recommended Posts