Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

Change Camera2Sample behavior to react on MediaStore intents for capt… #5

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Camera2Sample/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@
-->
<category android:name="com.google.android.glass.category.DIRECTORY"/>
</intent-filter>
<intent-filter>
<action android:name="android.media.action.IMAGE_CAPTURE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.media.action.VIDEO_CAPTURE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.media.action.STILL_IMAGE_CAMERA" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.media.action.VIDEO_CAMERA" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCaptureSession;
import android.hardware.camera2.CameraCaptureSession.CaptureCallback;
Expand All @@ -30,6 +31,7 @@
import android.hardware.camera2.params.StreamConfigurationMap;
import android.media.ImageReader;
import android.media.ImageReader.OnImageAvailableListener;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.Surface;
Expand Down Expand Up @@ -355,6 +357,26 @@ public void setPreviewSurface(Surface previewSurface) {
this.previewSurface = previewSurface;
}

/**
* Handles given {@link Intent} and sets appropriate {@link CameraMode} depends on the intent
* action.
*/
public void handleIntent(Intent intent) {
final String intentAction = intent.getAction();
if (intentAction != null) {
switch (intentAction) {
case MediaStore.ACTION_IMAGE_CAPTURE:
case MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA:
switchCameraMode(CameraMode.PICTURE);
break;
case MediaStore.INTENT_ACTION_VIDEO_CAMERA:
case MediaStore.ACTION_VIDEO_CAPTURE:
switchCameraMode(CameraMode.VIDEO);
break;
}
}
}

/**
* Switches {@link CameraMode} states. Possible scenarios:
* <ol>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
cameraActionHandler = new CameraActionHandler(getContext(), this);
cameraActionHandler.handleIntent(Objects.requireNonNull(getActivity()).getIntent());
}

@Override
Expand Down