To use an external file for the contents of the AlertDialog
try this:
`start_builder.setMessage(readRawTextFile(CONTEXT, R.raw.tos))
.setCancelable(false)
.setTitle(R.string.TOS_TITLE)
.setPositiveButton("Accept", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int id){
dialog.cancel(); // ToS accepted, run the program.
}
}) ...`
and the readRawTextFile()
method is defined as:
`/**
* Helper method to read in the text based files that are used to populate
* dialogs and other information used in the program.
*
* @param contex The context of the method call
* @param resId The resource ID of the text file from the \src\raw\ directory and registered
* in R.java.
* @return String Returns a String of the text contained in the resource file.
*/
public static String readRawTextFile(Context contex, int resId)
{
InputStream inputStream = contex.getResources().openRawResource(resId);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
int i;
try {
i = inputStream.read();
while (i != -1)
{
byteArrayOutputStream.write(i);
i = inputStream.read();
}
inputStream.close();
} catch (IOException e) {
return null;
}
return byteArrayOutputStream.toString();
}`
The last snippet is not mine, look here for the SO question that I got it from. Works great for displaying my EULA. Just move your source text file to the raw
directory and your in business!