Example usage for android.util Base64 DEFAULT

List of usage examples for android.util Base64 DEFAULT

Introduction

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

Prototype

int DEFAULT

To view the source code for android.util Base64 DEFAULT.

Click Source Link

Document

Default values for encoder/decoder flags.

Usage

From source file:com.ubiLive.GameCloud.Browser.WebBrowser.java

/**
 * For pphone protocol ,callback the purchase result
 * be invoked by Billingpphone purchase result interface.
 * @param bSuccess//from  www.  j  ava 2s . c  o  m
 * @param rsReceipt
 * @param strPurchaseGameSessionId
 */
public void notifyPurchaseResultByPphone(boolean bSuccess, String rsReceipt, String strPurchaseGameSessionId) {
    DebugLog.d(TAG, "call notifyPurchaseResultBypphone() bSuccess = " + bSuccess);
    String strCbPurchaseResult = "";
    if (bSuccess && rsReceipt != null && !"".equals(rsReceipt)) {
        byte[] licenseBytes = rsReceipt.getBytes();
        String base64license = Base64.encodeToString(licenseBytes, Base64.DEFAULT);
        strCbPurchaseResult = "{\"id\": \"" + strPurchaseGameSessionId + "\",\"type\": \"result\",\"code\": \""
                + Constants.RESPONSE_200 + "\",\"message\": \"success\"}";
        mReceiptMap.put(strPurchaseGameSessionId, base64license);

    } else {
        strCbPurchaseResult = "{\"id\": \"" + strPurchaseGameSessionId + "\",\"type\": \"result\",\"code\": \""
                + Constants.RESPONSE_600 + "\",\"message\": \"failure\"}";

    }
    DebugLog.d(TAG, "call notifyPurchaseResultBypphone() ubiGCPlayerCallback result = " + strCbPurchaseResult);
    ubiGCPlayerCallback("purchaseInApp", strCbPurchaseResult);
}

From source file:org.cryptsecure.Utility.java

/**
 * Load drawable image from a BASE64 encoded String.
 * //w w w  .j a  v a  2 s  . co m
 * @param encodedImage
 *            the encoded image
 * @return the drawable
 */
public static Drawable loadDrawableFromBASE64String(String encodedImage) {
    byte[] imageBytes = Base64.decode(encodedImage.getBytes(), Base64.DEFAULT);
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(imageBytes);
    Drawable drawable = Drawable.createFromStream(byteArrayInputStream, "attachment");
    return drawable;
}

From source file:com.ubiLive.GameCloud.Browser.WebBrowser.java

/**
 * Client -> client - >WebServer//from ww w  . ja v a  2s.co  m
 * BillingActivity
 * get the purchase result from billingActivity
 * will put the result to local receiptMap
 * @param bSuccess
 * @param license
 * @param strId ----session id (req -> res)
 */
public void notifyPurchaseResult(boolean bSuccess, String license, String strId) {
    DebugLog.d(TAG, "call notifyPurchaseResult() bSuccess = " + bSuccess);
    String request;
    /**
    {
        "id": "dsfdh34576dfgg76",
        "type": "result",
        "code": "200",
        "message": "success",
        "receipt": "xxxxx" //this xxxx stands for the base64 encoded license string
    }    
    */
    if (bSuccess && license != null) {

        byte[] licenseBytes = license.getBytes();
        String base64license = Base64.encodeToString(licenseBytes, Base64.DEFAULT);
        //request = "{\"id\": \""+ strId + "\",\"type\": \"result\",\"code\": \""+Constants.RESPONSE_200+"\",\"message\": \"success\",\"receipt\": \"" + base64license + "\"}";
        request = "{\"id\": \"" + strId + "\",\"type\": \"result\",\"code\": \"" + Constants.RESPONSE_200
                + "\",\"message\": \"success\"}";
        mReceiptMap.put(strId, base64license);
    } else {

        request = "{\"id\": \"" + strId + "\",\"type\": \"result\",\"code\": \"" + Constants.RESPONSE_500
                + "\",\"message\": \"failure\"}";
    }

    DebugLog.d(TAG, "javascript:playerNotification.notifyPurchaseResult. request = " + request);

    ubiGCPlayerCallback("purchaseInApp", request);

    mBillingStatus = Constants.BILLING_STATUS_END;
    sIsBillingTriggered = false;
}

From source file:org.cryptsecure.Utility.java

/**
 * Load a bitmap image from a BASE64 encoded String.
 * /*from  w w  w  .  jav  a  2  s  .  c om*/
 * @param context
 *            the context
 * @param encodedImage
 *            the encoded image
 * @return the bitmap
 */
public static Bitmap loadImageFromBASE64String(Context context, String encodedImage) {
    byte[] imageBytes = Base64.decode(encodedImage.getBytes(), Base64.DEFAULT);
    return getBitmapFromBytes(imageBytes);
}

From source file:com.android.launcher3.Utilities.java

public static void saveBitmapPref(Activity activity, String packageName, Bitmap realImage) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    realImage.compress(Bitmap.CompressFormat.PNG, 100, baos);
    byte[] b = baos.toByteArray();

    String encodedImage = Base64.encodeToString(b, Base64.DEFAULT);

    SharedPreferences shre = PreferenceManager.getDefaultSharedPreferences(activity);
    SharedPreferences.Editor edit = shre.edit();
    edit.putString(packageName, encodedImage);
    edit.commit();/*from  w  w w  .jav  a  2s  . com*/
}

From source file:com.android.launcher3.Utilities.java

public static Bitmap loadBitmapPref(Activity activity, String packageName) {
    SharedPreferences shre = PreferenceManager.getDefaultSharedPreferences(activity);
    String previouslyEncodedImage = shre.getString(packageName, "");

    if (!previouslyEncodedImage.equalsIgnoreCase("")) {
        byte[] b = Base64.decode(previouslyEncodedImage, Base64.DEFAULT);
        Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
        return bitmap;
    }//from   w ww  .  java 2s .co  m
    return null;
}

From source file:com.ubiLive.GameCloud.Browser.WebBrowser.java

/**
 * client -> client/*from   w ww  . j av  a  2s  .co m*/
 * BillingActivity
 * save all licenses in local HaspMap after do BillingActivity->checkInAppLicense()
 * @param sku
 * @param license
 */
public void notifyCheckLicenseResult(String sku, String license) {
    DebugLog.d(TAG, "0829 notifyCheckLicenseResult() sku= " + sku + ",license=" + license);
    String request;

    if (sku != null && license != null) {

        byte[] licenseBytes = license.getBytes();
        String base64license = Base64.encodeToString(licenseBytes, Base64.DEFAULT);
        DebugLog.d(TAG, "0829 notifyCheckLicenseResult() sku= " + sku + ",base64license=" + base64license);
        mCheckLicenseMap.put(sku, base64license);
    }
}

From source file:android.content.pm.PackageParser.java

public static final PublicKey parsePublicKey(final String encodedPublicKey) {
    if (encodedPublicKey == null) {
        Slog.w(TAG, "Could not parse null public key");
        return null;
    }/*from   ww  w.  j ava 2 s  .co  m*/

    EncodedKeySpec keySpec;
    try {
        final byte[] encoded = Base64.decode(encodedPublicKey, Base64.DEFAULT);
        keySpec = new X509EncodedKeySpec(encoded);
    } catch (IllegalArgumentException e) {
        Slog.w(TAG, "Could not parse verifier public key; invalid Base64");
        return null;
    }

    /* First try the key as an RSA key. */
    try {
        final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        return keyFactory.generatePublic(keySpec);
    } catch (NoSuchAlgorithmException e) {
        Slog.wtf(TAG, "Could not parse public key: RSA KeyFactory not included in build");
    } catch (InvalidKeySpecException e) {
        // Not a RSA public key.
    }

    /* Now try it as a ECDSA key. */
    try {
        final KeyFactory keyFactory = KeyFactory.getInstance("EC");
        return keyFactory.generatePublic(keySpec);
    } catch (NoSuchAlgorithmException e) {
        Slog.wtf(TAG, "Could not parse public key: EC KeyFactory not included in build");
    } catch (InvalidKeySpecException e) {
        // Not a ECDSA public key.
    }

    /* Now try it as a DSA key. */
    try {
        final KeyFactory keyFactory = KeyFactory.getInstance("DSA");
        return keyFactory.generatePublic(keySpec);
    } catch (NoSuchAlgorithmException e) {
        Slog.wtf(TAG, "Could not parse public key: DSA KeyFactory not included in build");
    } catch (InvalidKeySpecException e) {
        // Not a DSA public key.
    }

    /* Not a supported key type */
    return null;
}