Can't save photo in Android

Discussions about creating CAPI applications to run on Android devices
Forum rules
New release: CSPro 8.0
Post Reply
lusia
Posts: 49
Joined: March 28th, 2018, 4:56 am

Can't save photo in Android

Post by lusia »

I have a matter regarding on saving photos in Android. I use HP 7 Voice Tab, Advan Vandroid T1Q and Advan Vandroid S5E PRO (It's okay to mention the brand, isn't it?). The three of them can't save photo via csentry.
The logic is the same as another. Here is my script for Advan android (the path name is rather different from HP):

Code: Select all

PROC PHOTO_1
onfocus
	string NamePhoto = pathname(application) + 
					  maketext("Internal St/csentry/2018/2018_P/RESOURCES/PHOTO_E/PHOTO_E_%04d_1.jpg", ID_RESP);
					  
	if fileexist(NamePhoto) then
		setvalueset($, PHOTO_1_VS2);
	else
		setvalueset($, PHOTO_1_VS1);
	endif;
	
postproc
	if $ = 1 then
		//take/ retake photo
		execsystem(maketext("camera: %s", NamePhoto));
		reenter;
	elseif $ = 2 then
		//view foto
		execsystem(maketext("view: %s", NamePhoto));
		reenter;
	elseif $ = 3 then
		//Save photo
	elseif $ = 9 then
		//Refused
		if fileexist(NamePhoto) then
			filedelete(NamePhoto);
		endif;		
	endif;
And here is my script for HP 7 Voice Tab (I write the full pathname, just to make sure):

Code: Select all

PROC PHOTO_2
onfocus
	string NamePhoto = pathname(application) + 
					  maketext("My Storage/csentry/2018/2018_P/RESOURCES/PHOTO_E/PHOTO_E_%04d_2.jpg", ID_RESP);
					  
	if fileexist(NamePhoto) then
		setvalueset($, PHOTO_2_VS2);
	else
		setvalueset($, PHOTO_2_VS1);
	endif;
	
postproc
	if $ = 1 then
		//take/ retake photo
		execsystem(maketext("camera: %s", NamePhoto));
		reenter;
	elseif $ = 2 then
		//view foto
		execsystem(maketext("view: %s", NamePhoto));
		reenter;
	elseif $ = 3 then
		//Save photo
	elseif $ = 9 then
		//Refused
		if fileexist(NamePhoto) then
			filedelete(NamePhoto);
		endif;		
	endif;
I can take photos but I can't save them. The OK button is not disabled, but when I press it, it won't save photos in csentry. If I used the default camera from the device, it's no problem at all.
Idk what wrong is. It's okay when I used it (the script) for Samsung smartphone/tablet.

Kindly please help me.
Thank you before and after.

Regards,
lusia
aaronw
Posts: 561
Joined: June 9th, 2016, 9:38 am
Location: Washington, DC

Re: Can't save photo in Android

Post by aaronw »

The construction of the path assigned to NamePhoto looks incorrect. Remember the function pathname returns the path to the application folder. Try something like this:
string NamePhoto = pathname(application) + maketext("PHOTO_E_%04d_1.jpg", ID_RESP);
lusia
Posts: 49
Joined: March 28th, 2018, 4:56 am

Re: Can't save photo in Android

Post by lusia »

Dear aaronw,
Sorry for the late reply.
I've already done it as you suggested.
I have 19 photo items in my dictionary. And I created several folders for specific photo name, based on which section it is.
And I only changed the script for the first photo for section E. The rest, is the same as before. It works. I mean your suggestion works perfectly for my android. The photo can be saved. The problem is, the image is not saved in the right folder. For example, I want to save PHOTO_E_1201_1.jpg in folder PHOTO_E. But in fact, PHOTO_E_1201_1.jpg is saved in the same place of my .pff and .pen files.
Do you have any suggestion?

Thank you before and after.

Regards,
lusia
aaronw
Posts: 561
Joined: June 9th, 2016, 9:38 am
Location: Washington, DC

Re: Can't save photo in Android

Post by aaronw »

You will want to use a relative path and append this to what is returned from pathname(application).

As an example, take a look at the logic below. The pathname(application) returns an absolute path to the application folder. However, ".." moves us up a level and and then to PHOTO_E.
string NamePhoto = pathname(application) + "../PHOTO_E/" + maketext("PHOTO_E_%04d_1.jpg", ID_RESP);
lusia
Posts: 49
Joined: March 28th, 2018, 4:56 am

Re: Can't save photo in Android

Post by lusia »

Dear arronw,
Sorry for the late reply.
I've done it as you suggested. And your suggested code was not working.
But I did some trial and error.
My full path should be like this: InternalStorage/csentry/2018NS/2018NS/RESOURCES/PHOTO_E/
Here is the result of my trial:
1. without full path
the script is like this:

Code: Select all

string NamePhoto = pathname(application) + maketext("PHOTO_E_%04d_1.jpg", ID_RESP);
the photo is saved inside the second 2018NS folder. In this folder contains entry data file, 2018NS.pff and 2018NS.pen and .csdb

2. 1 slash(../)
the scripts are like this:

Code: Select all

string NamePhoto = pathname(application) + maketext("../PHOTO_E_%0_4d_1.jpg", ID_RESP);

Code: Select all

string NamePhoto = pathname(application) + "../" + maketext("PHOTO_E_%04d_1.jpg", ID_RESP);
the photo is saved inside the first 2018NS folder. In this folder contains synchronization.pff and synchronization.pen

3. 2 slash(../../)
the scripts are like this:

Code: Select all

string NamePhoto = pathname(application) + maketext("../../PHOTO_E_%04d_1.jpg", ID_RESP);

Code: Select all

string NamePhoto = pathname(application) + "../../" + maketext("PHOTO_E_%04d_1.jpg", ID_RESP);
the photo is saved inside the csentry folder.

4. 3 slash(../../../)
the scripts are like this:

Code: Select all

string NamePhoto = pathname(application) + maketext("../../../PHOTO_E_%04d_1.jpg", ID_RESP);

Code: Select all

string NamePhoto = pathname(application) + "../../../" + maketext("PHOTO_E_%04d_1.jpg", ID_RESP);
the photo is saved inside the InternalStorage folder.

My conclusion is the destination of the path for saving photo is reversed when I took and saved photo.
When I use "../../../../../PHOTO_E/" or "../PHOTO_E/", it didn't worked.

The photo I took should be saved in the folder PHOTO_E, but in reality it saved in the destination folder based on how much "../" I use.

So the last thing I've done is creating folder PHOTO_E in the second 2018NS folder.
And when I used the script below:

Code: Select all

string NamaFoto = pathname(application) + maketext("/PHOTO_E/PHOTO_E_%04d_1.jpg", ID_RESP);
It works. The photo is saved in the new PHOTO_E folder that I just created in the second 2018NS folder, not inside the "RESOURCES/PHOTO_E/" folder.

Do you have any other suggestion?
Because I think it's not proper.

Kindly please help me.

Thank you very much before and after.

Regards,
lusia
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Can't save photo in Android

Post by Gregory Martin »

If your application is in:

InternalStorage/csentry/2018NS/2018NS/

The pathname function will return the dictionary name with a trailing slash, so wouldn't your photo name be:
string NamaFoto = pathname(application) + maketext("RESOURCES/PHOTO_E/PHOTO_E_%04d_1.jpg", ID_RESP);
Make sure that the dictionary exists before you start to save photos into it.
Post Reply