Java tutorial
//package com.java2s; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import android.os.Build; public class Main { public static byte[] getBytes(String src, Charset charSet) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) { try { return src.getBytes(charSet.name()); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; } else { return src.getBytes(charSet); } } }