Android™
Android™
Example: Crypt2.EncodeString method
Demonstrates how to call the EncodeString method.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);
CkCrypt2 crypt = new CkCrypt2();
String s = "Hello World";
Log.i(TAG, crypt.encodeString(s,"utf-8","hex"));
// Output: 48656C6C6F20576F726C64
Log.i(TAG, crypt.encodeString(s,"utf-16","hex"));
// Output: 480065006C006C006F00200057006F0072006C006400
Log.i(TAG, crypt.encodeString(s,"utf-8","base64"));
// Output: SGVsbG8gV29ybGQ=
s = "électricité";
Log.i(TAG, crypt.encodeString(s,"utf-8","hex"));
// Output: C3A96C6563747269636974C3A9
Log.i(TAG, crypt.encodeString(s,"windows-1252","hex"));
// Output: E96C6563747269636974E9
Log.i(TAG, crypt.encodeString(s,"windows-1252","hex_lower"));
// Output: e96c6563747269636974e9
Log.i(TAG, crypt.encodeString(s,"utf-8","url"));
// Output: %C3%A9lectricit%C3%A9
}
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."
}
}