Example usage for android.util Base64 decode

List of usage examples for android.util Base64 decode

Introduction

In this page you can find the example usage for android.util Base64 decode.

Prototype

public static byte[] decode(byte[] input, int flags) 

Source Link

Document

Decode the Base64-encoded data in input and return the data in a new byte array.

Usage

From source file:Main.java

public static byte[] decode(String encodedData) {
    if (encodedData == null) {
        return null;
    }/* w  ww .j a v  a2  s. com*/
    return Base64.decode(encodedData, 0);
}

From source file:Main.java

/**
 * This method converts base64 string to bitmap.
 * /*  ww w.  j  av  a 2s.  c om*/
 * @param base64EncodedImage
 * @return bitmap
 */
public static Bitmap decodeFromBase64(String base64EncodedImage) {
    try {
        byte[] b = Base64.decode(base64EncodedImage, 0);
        return BitmapFactory.decodeByteArray(b, 0, b.length);
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static Bitmap convertStringToBitmap(String st) {
    // OutputStream out;
    Bitmap bitmap = null;//from   w w  w . j  av a  2  s.  c  o m
    try {
        // out = new FileOutputStream("/sdcard/aa.jpg");
        byte[] bitmapArray;
        bitmapArray = Base64.decode(st, Base64.DEFAULT);
        bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length);
        // bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
        return bitmap;
    } catch (Exception e) {
        return null;
    }
}

From source file:Main.java

public static Bitmap convertString2Icon(String st) {
    // OutputStream out;  
    Bitmap bitmap = null;/*from www  .  ja  va 2 s  .c  om*/
    try {
        // out = new FileOutputStream("/sdcard/aa.jpg");  
        byte[] bitmapArray;
        bitmapArray = Base64.decode(st, Base64.DEFAULT);
        bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length);
        // bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);  
        return bitmap;
    } catch (Exception e) {
        return null;
    }
}

From source file:Main.java

public static void base64ToBitmap(String base64Data, String imgName, String imgFormat) {
    byte[] bytes = Base64.decode(base64Data, Base64.DEFAULT);
    Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);

    File myCaptureFile = new File("/sdcard/", imgName);
    FileOutputStream fos = null;/*from w  ww .j  a v  a 2  s.  c om*/
    try {
        fos = new FileOutputStream(myCaptureFile);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block  
        e.printStackTrace();
    }
    boolean isTu = bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
    if (isTu) {
        // fos.notifyAll();  
        try {
            fos.flush();
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        try {
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:Main.java

public static String encodeCredentials(String username, String password) {
    String cred = username + ":" + password;
    String encodedValue = null;/* w w  w  .j  a  va2s.c om*/
    byte[] encodedBytes = Base64.encode(cred.getBytes(), Base64.NO_WRAP);
    encodedValue = new String(encodedBytes);
    System.out.println("encodedBytes " + new String(encodedBytes));
    byte[] decodedBytes = Base64.decode(encodedBytes, Base64.NO_WRAP);
    System.out.println("decodedBytes " + new String(decodedBytes));
    return encodedValue;
}

From source file:Main.java

static public byte[] decodeToByte(byte[] code) {
    if (code == null || code.length == 0) {
        return null;
    }/*ww  w  .  j  a v a2 s .c o m*/
    return Base64.decode(code, Base64.NO_WRAP);
}

From source file:Main.java

public static byte[] convertBase64IntoByte(String base64) {
    byte[] decodedString = Base64.decode(base64, Base64.DEFAULT);
    return decodedString;
}

From source file:Main.java

public static RSAPublicKey buildPublicKeyFromBase64String(String key)
        throws InvalidKeySpecException, NoSuchAlgorithmException {
    byte[] byteKey = Base64.decode(key.getBytes(), Base64.NO_WRAP | Base64.URL_SAFE);
    X509EncodedKeySpec X509publicKey = new X509EncodedKeySpec(byteKey);
    KeyFactory kf = KeyFactory.getInstance("RSA");

    return (RSAPublicKey) kf.generatePublic(X509publicKey);
}

From source file:Main.java

public static byte[] decode(String base64) throws Exception {
    return Base64.decode(base64.getBytes(), Base64.NO_PADDING);
}