Android™
Android™
Detect the Primary Language Group of an Email
See more Email Object Examples
Demonstrates the read-only Chilkat Email.Language property, which identifies the primary language group detected in the email's subject and body text, returning values such as latin1, russian, or japanese. The Subject has the greatest influence on the result. This example sets English text and reads the detected language.
Background: This is a heuristic based on Unicode: every character belongs to a Unicode "block" (Latin, Cyrillic, Greek, CJK, etc.), and Chilkat classifies the message by which blocks its characters fall into. The goal is practical — choosing a suitable charset/encoding for the text — not formal linguistic detection. It does not read the MIME
Content-Language header, and it ignores characters in address and other header fields.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 read-only Email.Language property, a character-based
// heuristic that identifies the primary language group detected in the
// email's subject and body text (e.g. latin1, russian, japanese, ...).
CkEmail email = new CkEmail();
email.put_Subject("Hello, this is an English subject line.");
email.put_Body("This is the body text, written in English.");
// The Subject has the greatest influence on the result.
Log.i(TAG, "Language = " + email.language());
}
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."
}
}