[JAVA] Technical causes and countermeasures for the points that I was addicted to with the Android app & Kotlin (2. Processing related to the camera function of Android *)

2. * Android * camera function processing

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.

2.1 * Chooser * processing to select the gallery or camera function when selecting an image

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

2.2 Processing to exclude other camera apps from the camera function of * Chooser *

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

2.3 * Intent * parameter processing of * onActivityResult () * when shooting with camera

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

Link

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

Technical causes and countermeasures for the points that I was addicted to with the Android app & Kotlin (2. Processing related to the camera function of Android *)
Technical causes and countermeasures for the points I was addicted to with the first Android app & Kotlin
Technical causes and countermeasures for points addicted to Android apps & Kotlin (3. Processing related to Android images)
Technical causes and countermeasures for points addicted to Android apps & Kotlin (3. Processing related to Android images)
Technical causes and countermeasures for the points I was addicted to with the first Android app & Kotlin
Technical causes and countermeasures for the points that I was addicted to with the Android app & Kotlin (2. Processing related to the camera function of Android *)
[Android / Java] Screen transition and return processing in fragments
Convert all Android apps (Java) to Kotlin
Summary of good points and precautions when converting Java Android application to Kotlin
Specify Java / Kotlin compile-time options for Android apps
A story that I was addicted to twice with the automatic startup setting of Tomcat 8 on CentOS 8
I was addicted to the record of the associated model
A memo that I was addicted to when making batch processing with Spring Boot
A memorandum because I was addicted to the setting of the Android project of IntelliJ IDEA
I tried to summarize the basics of kotlin and java
I want to make a function with kotlin and java!
I was addicted to the setting of laradock + VSCode + xdebug
What I was addicted to with the Redmine REST API
I want to return to the previous screen with kotlin and java!
The story of Collectors.groupingBy that I want to keep for posterity
[Swift 5] Processing and precautions for transitioning to the iOS settings app
About the matter that I was addicted to how to use hashmap
I was addicted to the API version min23 setting of registerTorchCallback
A memo that was soberly addicted to the request of multipart / form-data
Problems I was addicted to when building the digdag environment with docker
Recorded because I was addicted to the standard input of the Scanner class
I tried to summarize the key points of gRPC design and development
The story of releasing the Android app to the Play Store for the first time.
[CircleCI] I was addicted to the automatic test of CircleCI (rails + mysql) [Memo]
I was addicted to unit testing with the buffer operator in RxJava
I tried to measure and compare the speed of GraalVM with JMH
I was addicted to the roll method
I was addicted to the Spring-Batch test
Summary of good points and precautions when converting Java Android application to Kotlin
Summary of points I was worried about when migrating from java to kotlin
I was addicted to doing onActivityResult () with DialogFragment
The part I was addicted to in "Introduction to Ajax in Java Web Applications" of NetBeans
What I did to get out of the first wall I was assigned to the SRE team and bumped into, "What should I start with?"