Android™
Android™
Generate a Unique Filename for an Email
See more Email Object Examples
Demonstrates the Chilkat Email.GenerateFilename method, which generates a unique filename for the email. The returned filename is different each time the method is called. This example generates one and prints it.
Background: When saving many messages to a folder — for example exporting a mailbox to
.eml files — you need a distinct name for each so they do not overwrite one another. GenerateFilename produces a fresh, collision-resistant name on demand, sparing you from inventing your own scheme (timestamps, counters, GUIDs) just to keep files from clashing.Chilkat Android™ Downloads
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
private static final String TAG = "Chilkat";
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Demonstrates the GenerateFilename method, which generates a unique filename for this
// email. The filename is different each time the method is called.
CkEmail email = new CkEmail();
email.put_Subject("Weekly report");
// Generate a unique filename (for example, to save the email to disk).
String fname = email.generateFilename();
Log.i(TAG, "Generated filename: " + fname);
}
static {
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}