Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit c69b392

Browse files
committed
[[ Bug 22664 ]] Add support for front camera in Android mobilePickPhoto
This patch updates `mobilePickPhoto` to handle `front camera` and `rear camera` enum values for the source parameter.
1 parent d25ddb2 commit c69b392

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

docs/dictionary/command/mobilePickPhoto.lcdoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ The source for the image.
2828
- "library":
2929
- "album":
3030
- "camera":
31-
- "rear camera": iOS only
32-
- "front camera": iOS only
31+
- "rear camera":
32+
- "front camera":
3333

3434

3535
maxwidth:

docs/notes/bugfix-22664.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Support `mobilePickPhoto "front camera"` on Android

engine/src/java/com/runrev/android/Engine.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,8 +2080,8 @@ public void showPhotoPicker(String p_source, int p_width, int p_height)
20802080
m_photo_width = p_width;
20812081
m_photo_height = p_height;
20822082

2083-
if (p_source.equals("camera"))
2084-
showCamera();
2083+
if (p_source.contains("camera"))
2084+
showCamera(p_source);
20852085
else if (p_source.equals("album"))
20862086
showLibrary();
20872087
else if (p_source.equals("library"))
@@ -2099,7 +2099,7 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in
20992099
onAskPermissionDone(grantResults[0] == PackageManager.PERMISSION_GRANTED);
21002100
}
21012101

2102-
public void showCamera()
2102+
public void showCamera(String p_source)
21032103
{
21042104
// 2012-01-18-IM temp file may be created in app cache folder, in which case
21052105
// the file needs to be made world-writable
@@ -2149,6 +2149,20 @@ public void showCamera()
21492149
t_uri = FileProvider.getProvider(getContext()).addPath(t_path, t_path, "image/jpeg", true, ParcelFileDescriptor.MODE_READ_WRITE);
21502150

21512151
Intent t_image_capture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
2152+
2153+
if (p_source.equals("front camera"))
2154+
{
2155+
t_image_capture.putExtra("android.intent.extras.CAMERA_FACING", 1);
2156+
t_image_capture.putExtra("android.intent.extras.LENS_FACING_FRONT", 1);
2157+
t_image_capture.putExtra("android.intent.extra.USE_FRONT_CAMERA", true);
2158+
2159+
}
2160+
else if (p_source.equals("rear camera"))
2161+
{
2162+
t_image_capture.putExtra("android.intent.extras.CAMERA_FACING", 0);
2163+
t_image_capture.putExtra("android.intent.extras.LENS_FACING_FRONT", 0);
2164+
t_image_capture.putExtra("android.intent.extra.USE_FRONT_CAMERA", false);
2165+
}
21522166
t_image_capture.putExtra(MediaStore.EXTRA_OUTPUT, t_uri);
21532167
t_image_capture.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
21542168
t_activity.startActivityForResult(t_image_capture, IMAGE_RESULT);

engine/src/mblandroidcamera.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,12 @@ static const char *MCPhotoSourceTypeToCString(MCPhotoSourceType p_source)
106106
case kMCPhotoSourceTypeAlbum:
107107
return "album";
108108
case kMCPhotoSourceTypeCamera:
109-
case kMCPhotoSourceTypeFrontCamera:
110-
case kMCPhotoSourceTypeRearCamera:
111-
return "camera";
112-
default:
109+
return "camera";
110+
case kMCPhotoSourceTypeRearCamera:
111+
return "rear camera";
112+
case kMCPhotoSourceTypeFrontCamera:
113+
return "front camera";
114+
default:
113115
MCUnreachableReturn("unknown");
114116
}
115117

0 commit comments

Comments
 (0)