On Android you can use execsystem("view:<pathtotextfile>"). If your text file is named myfile.txt in the csentry directory then you could do:
execsystem("view:/sdcard/csentry/myfile.txt")
you can also place text files in your application directory (the folder where your .pen file is) and then use the pathname() function to get the path to them:
execsystem(maketext("view:%smyfile.txt", pathname(Application))
Depending on what app is set to view text files on your Android device you may or may not have trouble with formatting. On a couple of devices I have tried the default text viewer does not used a fixed width font which makes it hard to format the text nicely. If that is a problem you may want to look at using HTML instead of text.
Here is an example function that writes out a text file to the application directory and displays a simple text file (works on both Android and Windows):
// Write out and display household summary report
function showHouseholdReport()
string reportFilename = maketext("%sreport.txt", pathname(Application));
setfile(tempFile, reportFilename);
filewrite(tempFile, "Household Summary Report");
filewrite(tempFile, "------------------------");
filewrite(tempFile, "");
filewrite(tempFile, "District %d Village %d Household Number %d",
visualvalue(DISTRICT),
visualvalue(VILLAGE),
visualvalue(HOUSEHOLD_NUMBER));
filewrite(tempFile, "");
filewrite(tempFile, "Members 5 years and over:");
filewrite(tempFile, "");
numeric i;
filewrite(tempFile, "Name Sex Age Relationship");
filewrite(tempFile, "---- --- --- ------------");
do i = 1 while i < totocc(ADULTS000)
filewrite(tempFile, "%s %-6s %3d %s",
NAME(i),
getlabel(SEX, visualvalue(SEX(i))),
visualvalue(AGE(i)),
getlabel(RELATIONSHIP_VS1, visualvalue(RELATIONSHIP(i))));
enddo;
close(tempFile);
if getos() in 20:29 then
// Android - use "view:"
execsystem(maketext("view:%s", reportFilename));
else
// Windows - use "explorer.exe <filename>"
execsystem(maketext("explorer.exe %s", reportFilename));
endif;
end;
Here is a similar example but using HTML:
// Write out and display household summary report using HTML
function showHouseholdReportHTML()
string reportFilename = maketext("%sreport.html", pathname(Application));
setfile(tempFile, reportFilename);
filewrite(tempFile, "<!DOCTYPE html>");
filewrite(tempFile, "<html><head>");
filewrite(tempFile, "<style type='text/css'>");
filewrite(tempFile, "table, th, td {border: 1px solid black;border-collapse: collapse;padding: 8px}");
filewrite(tempFile, "</style>");
filewrite(tempFile, "<title>Household Summary Report</title>");
filewrite(tempFile, "</head>");
filewrite(tempFile, "<body>");
filewrite(tempFile, "<h2>Household Summary Report</h2>");
filewrite(tempFile, "<p>District: %d</p>",
visualvalue(DISTRICT));
filewrite(tempFile, "<p>Village: %d</p>",
visualvalue(VILLAGE));
filewrite(tempFile, "<p>Household Number %d</p>",
visualvalue(HOUSEHOLD_NUMBER));
filewrite(tempFile, '<img src="photos/photo-%d-%02d-%03d.jpg" alt="household photo" width="300">',
visualvalue(DISTRICT), visualvalue(VILLAGE),
visualvalue(HOUSEHOLD_NUMBER));
filewrite(tempFile, "<p>Members 5 years and over:</p>");
numeric i;
filewrite(tempFile, "<table>");
filewrite(tempFile, "<tr><th>Name</th><th>Sex</th><th>Age</th><th>Relationship</th></tr>");
do i = 1 while i < totocc(ADULTS000)
filewrite(tempFile, "<tr>");
filewrite(tempFile, "<td>%s</td>", NAME(i));
filewrite(tempFile, "<td>%s</td>",
getlabel(SEX, visualvalue(SEX(i))));
filewrite(tempFile, "<td>%d</td>", visualvalue(AGE(i)));
filewrite(tempFile, "<td>%s</td>",
getlabel(RELATIONSHIP_VS1,
visualvalue(RELATIONSHIP(i))));
filewrite(tempFile, "</tr>");
enddo;
filewrite(tempFile, "</table>");
filewrite(tempFile, "</body></html>");
close(tempFile);
if getos() in 20:29 then
// Android - use "view:"
execsystem(maketext("view:%s", reportFilename));
else
// Windows - use "explorer.exe <filename>"
execsystem(maketext("%sexplorer.exe %s",
pathname(Windows),
reportFilename));
endif;
end;