FLIR Mobile Developer / Blog / Topics / app, Best, Cheap, development, mobile / Problem in saving images on Android

Problem in saving images on Android

Home Forums FLIR developer community General discussion Problem in saving images on Android

This topic contains 12 replies, has 9 voices, and was last updated by Profile photo of William William 1 month ago.

Viewing 13 posts - 1 through 13 (of 13 total)

  • Author

    Posts

  • #7326

    Profile photo of Charles
    Charles

    Participant

    I am writing an app starting from the example provided by FLIR. I am having a problem with saving images. The problem is that, although the logger says the file was saved and there is no exception message, I can’t find any saved image on my Samsung phone. It is supposed to show up in the DCIM folder, right? In my case, I use the Android Studio and connect to a Samsung phone when running the app. And I use the simulated device for testing this and also confirmed that it didn’t work either when I plugged in the real FLIR ONE camera. Here is my slightly modified code for saving images:</p>

            //Capture this image if requested
            if (imageCaptureRequested) {
                imageCaptureRequested = false;
                String formattedDate = dateFormat.format(new Date());
                final String fileName = "smartir-" + formattedDate + ".jpg";
                final Context context = this;
                new Thread(new Runnable() {
                    public void run() {
                        final String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath();
                        try {
                            lastSavedPath = path + "/" + fileName;
                            // MediaStore.Images.Media.insertImage(getContentResolver(), thermalBitmap, fileName, "smartir");
                            renderedImage.getFrame().save(new File(lastSavedPath), frameProcessor);
                            MediaScannerConnection.scanFile(context,
                                    new String[]{lastSavedPath}, null,
                                    new MediaScannerConnection.OnScanCompletedListener() {
                                        @Override
                                        public void onScanCompleted(String path, Uri uri) {
                                            Log.i("ExternalStorage", "Scanned " + path + ":");
                                            Log.i("ExternalStorage", "-> uri=" + uri);
                                        }
                                    });
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                thermalImageView.animate().setDuration(50).scaleY(0).withEndAction((new Runnable() {
                                    public void run() {
                                        Toast.makeText(getApplicationContext(), "Saved to " + path, Toast.LENGTH_SHORT).show();
                                        thermalImageView.animate().setDuration(50).scaleY(1);
                                    }
                                }));
                            }
                        });
                    }
                }).start();
    

    <p>I googled this problem and most posts say this should just work fine, but it doesn’t work for me. I would appreciate if someone in this community can enlighten me!

    • This topic was modified 3 years ago by Profile photo of Charles Charles.
    • This topic was modified 3 years ago by Profile photo of Charles Charles.
    • This topic was modified 3 years ago by Profile photo of Charles Charles.

    #7331

    Profile photo of Charles
    Charles

    Participant

    Update: I found it would work if I granted the app the Storage Permission through the Application Manager. And the images showed up in the Pictures folder as expected. The question now is: Doesn’t it already have the permission according to the manifest from the original example by FLIR:

        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
        <uses-permission android:name="android.permission.INTERNET"/>
    

    Do we still have to turn the permissions on manually even in the development mode?

    #7357

    Profile photo of Allison
    Allison

    Moderator

    Hi Charles,

    Glad you were able to get it working. In response to your last question, yes, you will still have to turn on permissions manually even in development mode. It’s built into the Android OS that permissions must be enabled.

    Let me know if any more issues come up and I will be happy to help.

    Thank you,
    Allison Torchia

    #7360

    Profile photo of Charles
    Charles

    Participant

    Is there a way to throw an exception that can be caught so that we can warn the user if this permission is not given? Or perhaps we can check the permission first and remind the user if it is not already granted. If I remember correctly, I didn’t see an exception in the console, which was what caught me.

    #7361

    Profile photo of Allison
    Allison

    Moderator

    Hi Charles,

    You should be able to do this with Runtime requests, here is a link to Android development documentation that covers permissions. That should get you started to implement a window that asks the user for permissions.

    Thank you,
    Allison Torchia

    #8848

    Profile photo of Sebastian
    Sebastian

    Participant

    his Blog highlights the issues that you may face when you capture pictures through a mobile or camera but they do not get saved in the picture gallery. It is an annoying situation as you are not able to view the moments Viva Video

    #8907

    Profile photo of Boyd
    Boyd

    Participant

    No i guess there is no way to do so…Permission is necessary to warn the user in case of exception throwing mykfcexperience

    #11900

    Profile photo of maya
    maya

    Participant

    in exception throwing, you should write the proper logic, as of my knowledge it is not correct https://www.mykfcexperience.xyz/

    #14506

    Profile photo of fernodz
    fernodz

    Participant

    Finally, I have observed this issue on my android while taking the panda express feedback survey and I lost a chance to win a free meals coupon. Hope it resolves soon

    #18450

    Profile photo of john
    john

    Participant

    No i guess there is no way to do so…Permission is necessary to warn the user in case of exception throwing mykfcexperience<br />

    </p>
    yes youre right with the things you said

    • This reply was modified 8 months, 2 weeks ago by Profile photo of john john.
    • This reply was modified 8 months, 2 weeks ago by Profile photo of john john.

    #32436

    Profile photo of Nala
    Nala

    Participant

    Is there a way to throw an exception that can be caught so that we can warn the user if this permission is not given? Or perhaps we can check the permission first and remind the user if it is not already granted.

    #32450

    Profile photo of Nala
    Nala

    Participant

    Is there a way to throw an exception that can be caught so that we can warn the user if this permission is not given? Or perhaps we can check the permission first and remind the user if it is not already granted. krnl

    #33253

    Profile photo of William
    William

    Participant

    Thanks for the step by step tutorial. Works like a charm! The solution worked for me thanks to the community and the members for the solution.

Viewing 13 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic.