How to Save Captured Image to Gallery codename one?

Viewed 238

I have been working on a solution that involves capturing the image from codename one application and store it in the gallery but based on the documentation I have seen that the image is temporary file , I need a code to copy that file into the gallery so I can get it anytime that I want

code so far :

String imageName = "Hello.png";
    String filePath = Capture.capturePhoto();
    if(filePath != null) {
        try {
            Util.copy(FileSystemStorage.getInstance().openInputStream(filePath), Storage.getInstance().createOutputStream(imageName));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

I need to inject the code where I replace Storage.getInstance().createOutputStream(imageName)

with full path of gallery

I found that there is a native library called CameraKit :

Exception when trying the camera kit

I tried the demo on iOS [ tried on iPhone 7 ] and it caused the following exception when press to capture the image

=================================================================
Main Thread Checker: UI API called on a background thread: -[UIView bounds]
PID: 370, TID: 26983, Thread name: (none), Queue name: com.apple.root.default-qos.overcommit, QoS: 21
Backtrace:
4   MyApplication                       0x00000001049f829c Java_com_codename1_impl_ios_IOSImplementation_getDisplayWidthImpl + 80
5   MyApplication                       0x0000000104bf379c com_codename1_impl_ios_IOSNative_getDisplayWidth__ + 76
6   MyApplication                       0x0000000104c05478 com_codename1_impl_ios_IOSNative_getDisplayWidth___R_int + 32
7   MyApplication                       0x0000000104a0f4cc com_codename1_impl_ios_IOSImplementation_getDisplayWidth___R_int + 268
8   MyApplication                       0x0000000104a1a1e4 virtual_com_codename1_impl_ios_IOSImplementation_getDisplayWidth___R_int + 96
9   MyApplication                       0x0000000104a3d6a0 com_codename1_impl_ios_IOSImplementation_convertToPixels___int_boolean_R_int + 408
10  MyApplication                       0x00000001049ae150 virtual_com_codename1_impl_CodenameOneImplementation_convertToPixels___int_boolean_R_int + 112
11  MyApplication                       0x0000000104608b2c com_codename1_ui_Display_convertToPixels___float_R_int + 308
12  MyApplication                       0x000000010466c09c com_codename1_ui_plaf_UIManager_resetThemeProps___java_util_Hashtable + 2620
13  MyApplication                       0x000000010466b618 com_codename1_ui_plaf_UIManager___INIT____ + 2476
14  MyApplication                       0x000000010467e090 com_codename1_ui_plaf_UIManager_getInstance___R_com_codename1_ui_plaf_UIManager + 416
15  MyApplication                       0x00000001045f013c com_codename1_ui_Display_mainEDTLoop__ + 1016
16  MyApplication                       0x00000001049d0e00 com_codename1_ui_RunnableWrapper_run__ + 7124
17  MyApplication                       0x00000001048e7fb4 virtual_java_lang_Runnable_run__ + 160
18  MyApplication                       0x0000000104875478 com_codename1_impl_CodenameOneThread_run__ + 548
19  MyApplication                       0x00000001048e7fb4 virtual_java_lang_Runnable_run__ + 160
20  MyApplication                       0x0000000104809a70 java_lang_Thread_runImpl___long + 1056
21  MyApplication                       0x00000001047b3c04 threadRunner + 80
22  libsystem_pthread.dylib             0x00000001823f1220 <redacted> + 272
23  libsystem_pthread.dylib             0x00000001823f1110 <redacted> + 0
24  libsystem_pthread.dylib             0x00000001823efb10 thread_start + 4
2018-09-17 11:39:50.457427+0300 MyApplication[370:26983] [reports] Main Thread Checker: UI API called on a background thread: -[UIView bounds]
PID: 370, TID: 26983, Thread name: (none), Queue name: com.apple.root.default-qos.overcommit, QoS: 21
Backtrace:
4   MyApplication                       0x00000001049f829c Java_com_codename1_impl_ios_IOSImplementation_getDisplayWidthImpl + 80
5   MyApplication                       0x0000000104bf379c com_codename1_impl_ios_IOSNative_getDisplayWidth__ + 76
6   MyApplication                       0x0000000104c05478 com_codename1_impl_ios_IOSNative_getDisplayWidth___R_int + 32
7   MyApplication                       0x0000000104a0f4cc com_codename1_impl_ios_IOSImplementation_getDisplayWidth___R_int + 268
8   MyApplication                       0x0000000104a1a1e4 virtual_com_codename1_impl_ios_IOSImplementation_getDisplayWidth___R_int + 96
9   MyApplication                       0x0000000104a3d6a0 com_codename1_impl_ios_IOSImplementation_convertToPixels___int_boolean_R_int + 408
10  MyApplication                       0x00000001049ae150 virtual_com_codename1_impl_CodenameOneImplementation_convertToPixels___int_boolean_R_int + 112
11  MyApplication                       0x0000000104608b2c com_codename1_ui_Display_convertToPixels___float_R_int + 308
12  MyApplication                       0x000000010466c09c com_codename1_ui_plaf_UIManager_resetThemeProps___java_util_Hashtable + 2620
13  MyApplication                       0x000000010466b618 com_codename1_ui_plaf_UIManager___INIT____ + 2476
14  MyApplication                       0x000000010467e090 com_codename1_ui_plaf_UIManager_getInstance___R_com_codename1_ui_plaf_UIManager + 416
15  MyApplication                       0x00000001045f013c com_codename1_ui_Display_mainEDTLoop__ + 1016
16  MyApplication                       0x00000001049d0e00 com_codename1_ui_RunnableWrapper_run__ + 7124
17  MyApplication                       0x00000001048e7fb4 virtual_java_lang_Runnable_run__ + 160
18  MyApplication                       0x0000000104875478 com_codename1_impl_CodenameOneThread_run__ + 548
19  MyApplication                       0x00000001048e7fb4 virtual_java_lang_Runnable_run__ + 160
20  MyApplication                       0x0000000104809a70 java_lang_Thread_runImpl___long + 1056
21  MyApplication                       0x00000001047b3c04 threadRunner + 80
22  libsystem_pthread.dylib             0x00000001823f1220 <redacted> + 272
23  libsystem_pthread.dylib             0x00000001823f1110 <redacted> + 0
24  libsystem_pthread.dylib             0x00000001823efb10 thread_start + 4
2018-09-17 11:39:52.007930+0300 MyApplication[370:26735] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2018-09-17 11:39:52.009349+0300 MyApplication[370:26735] [MC] Reading from public effective user settings.
2018-09-17 11:39:52.788626+0300 MyApplication[370:26983] Failed to create directory /var/mobile/Containers/Data/Application/02F1D9AF-FE59-4B2B-9DC8-857338A52F07/Documents/cn1storage/
2018-09-17 11:39:52.832746+0300 MyApplication[370:26983] [Unknown process name] CGContextSetAllowsAntialiasing: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2018-09-17 11:39:52.883682+0300 MyApplication[370:26983] [Unknown process name] CGContextSetAllowsAntialiasing: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2018-09-17 11:39:56.810978+0300 MyApplication[370:26735] *** Terminating app due to uncaught exception 'NSGenericException', reason: '*** -[AVCapturePhotoOutput capturePhotoWithSettings:delegate:] No active and enabled video connection'
*** First throw call stack:
(0x1827cad8c 0x1819845ec 0x188369924 0x104ded220 0x105da51dc 0x105da519c 0x105da9d2c 0x182773070 0x182770bc8 0x182690da8 0x184676020 0x18c6b0758 0x104bf3728 0x104a0ebd4 0x1049ae238 0x1045e6a8c 0x104e01230 0x104e0129c 0x182121fc0)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

Regards,

1 Answers

This copies the image to your local storage. You can copy it to your local filesystem home directory too but you can't copy it into the device gallery.

For that you need an explicit API to store the image file there. Some camera and OS implementations store images in the gallery and some don't. Unfortunately it's not something that's easy to control generically.

Related