Thursday 24 January 2013

Convert String in to base64 in Android

Convert String in to base64 in Android

byte[] data;

              String str = "xyzstring";

              try {

                     data = str.getBytes("UTF-8");

                     String base64 = Base64.encodeToString(data, Base64.DEFAULT);

                     Log.i("Base 64 ", base64);

              } catch (UnsupportedEncodingException e) {



Base 64 of "xyzstring" is “eHl6c3RyaW5n”

Our new android application for EGreeting.Have a look to it.
The Greetings Android Application 

NovaRadix Android Application Development Team
NovaRadix Technology


  1. Thanks for your sharing,i learn a lot.Can you tell me the code to transform a image (maximum of 200KB) into Base64 String?

    I need to know how to do it with android, because I have to add the functionality to upload images to a remote server in my main app putting them into a row of the database, as a string.

    I am searching in google and in StackOverflow but I could not find easy examples that I can afford and also I find some examples but they are not talking about to transform into String. Then I need to transform into string to upload by JSON to my remote server.
    android qrcode generation

  2. Thanks for your good information and short example to Convert String in to base64 in Android. Find more tutorials: Android volley post json request example


Call web services easily

get source code from here, Download