Controlling Camera Actions Using Voice Interaction in Phimpme Android
In this blog, I will explain how I implemented Google voice actions to control camera features on the Phimpme Android project. I will cover the following features I have implemented on the Phimpme project: Opening the application using Google Voice command. Switching between the cameras. Clicking a Picture and saving it through voice command. Opening application when the user gives a command to Google Now. When the user gives command “Take a selfie” or “Click a picture” to Google Now it directly opens Phimpme camera activity. First We need to add an intent filter to the manifest file so that Google Now can detect Phimpme camera activity <activity android:name=".opencamera.Camera.CameraActivity" android:screenOrientation="portrait" android:theme="@style/Theme.AppCompat.NoActionBar"> <intent-filter> <action android:name="android.media.action.IMAGE_CAPTURE"/> <category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.VOICE"/> </intent-filter> </activity> category android:name=”android.intent.category.VOICE” is added to the IMAGE_CAPTURE intent filter for the Google Now to detect the camera activity. For the Google Now assistance to accept the command in the camera activity we need to add the following in the STILL_IMAGE_CAMERA intent filter in the camera activity. <intent-filter> <action android:name="android.media.action.STILL_IMAGE_CAMERA"/> <category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.VOICE"/> </intent-filter> So, now when the user says “OK Google” and “Take a Picture” the camera activity on Phimpme opens. Integrating Google Voice assistance in Camera Activity Second, After opening the camera application the Google Assistance should ask a question. The cameraActivity in Phimpme can be opened in two ways, such as: When opened from a different application. When given the command to Goole Now assistance. We need to check whether the camera activity is prompted from Google assistance or not to activate voice command. We will check it in onResume function. @Override public void onResume() { if (CameraActivity.this.isVoiceInteraction()) { startVoiceTrigger(); } } If is.VoiceInteraction gives “true” then voice Assistance prompts. Assistance to ask which camera to use Third, …
