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.aidy.launcher3.ui.receiver.InstallShortcutReceiver.java

private static void addToInstallQueue(SharedPreferences sharedPrefs, PendingInstallShortcutInfo info) {
    synchronized (sLock) {
        try {//  w  w  w . ja  v  a 2s  .c om
            JSONStringer json = new JSONStringer().object().key(DATA_INTENT_KEY).value(info.data.toUri(0))
                    .key(LAUNCH_INTENT_KEY).value(info.launchIntent.toUri(0)).key(NAME_KEY).value(info.name);
            if (info.icon != null) {
                byte[] iconByteArray = ItemInfoBean.flattenBitmap(info.icon);
                json = json.key(ICON_KEY)
                        .value(Base64.encodeToString(iconByteArray, 0, iconByteArray.length, Base64.DEFAULT));
            }
            if (info.iconResource != null) {
                json = json.key(ICON_RESOURCE_NAME_KEY).value(info.iconResource.resourceName);
                json = json.key(ICON_RESOURCE_PACKAGE_NAME_KEY).value(info.iconResource.packageName);
            }
            json = json.endObject();
            SharedPreferences.Editor editor = sharedPrefs.edit();
            if (DBG)
                Log.d(TAG, "Adding to APPS_PENDING_INSTALL: " + json);
            addToStringSet(sharedPrefs, editor, APPS_PENDING_INSTALL, json.toString());
            editor.commit();
        } catch (org.json.JSONException e) {
            Log.d(TAG, "Exception when adding shortcut: " + e);
        }
    }
}

From source file:com.example.administrator.winsoftsalesproject.activity.NavHomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_nav_home);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from  w w w. j  a  v a2  s . c  o  m
    sessionManger = new SessionManger(this);
    sessionManger.checkLogin();
    HashMap<String, String> user = sessionManger.getUserDetails();
    home = new Home();
    fragmentTransaction(home);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    View header = navigationView.getHeaderView(0);
    TextView headerName = (TextView) header.findViewById(R.id.nav_name);
    TextView designation = (TextView) header.findViewById(R.id.nav_designation);
    ImageView headerImage = (ImageView) header.findViewById(R.id.nav_image);

    headerName.setText(user.get(sessionManger.KEY_EMPLOYEE_NAME).toUpperCase());
    designation.setText(user.get(sessionManger.KEY_DEPARTMENT).toUpperCase());

    byte[] decodeString = Base64.decode(user.get(sessionManger.KEY_EMPLOYEE_PHOTO).getBytes(), Base64.DEFAULT);
    Bitmap bitmap = BitmapFactory.decodeByteArray(decodeString, 0, decodeString.length);
    headerImage.setImageBitmap(bitmap);
}

From source file:com.ibm.mobileclientaccess.fbauth.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    infoTextView = (TextView) findViewById(R.id.info);

    MCAAuthorizationManager.createInstance(this);

    Logger.setSDKDebugLoggingEnabled(true);

    /*//from ww  w  .  j  a va  2s.c om
    There may be issues with the hash key for the app, because it may not be correct when using from command line
    https://developers.facebook.com/docs/android/getting-started#release-key-hash (troubleshoot section)
    Add this code (and remove after getting the correct key (debug? release)) for this will print to log the correct hash code.
     */
    try {
        PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    } catch (PackageManager.NameNotFoundException e) {
    } catch (NoSuchAlgorithmException e) {
    }

    try {
        //Register to the server with backendroute and GUID
        BMSClient.getInstance().initialize(this, backendRoute, backendGUID, BMSClient.REGION_UK);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }

    // Register the default delegate for Facebook
    FacebookAuthenticationManager.getInstance().register(this);
    Logger.setSDKDebugLoggingEnabled(true);
}

From source file:com.remobile.cordova.CordovaArgs.java

public byte[] getArrayBuffer(int index) throws JSONException {
    String encoded = baseArgs.getString(index);
    return Base64.decode(encoded, Base64.DEFAULT);
}

From source file:com.facebook.samples.sessionlogin.LoginUsingActivityActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity);/*from www. j  a v a2  s  .com*/
    Log.v("msg", "hello");
    try {
        PackageInfo info = getPackageManager().getPackageInfo("com.facebook.samples.sessionlogin",
                PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    } catch (NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }

    buttonLoginLogout = (Button) findViewById(R.id.buttonLoginLogout);
    textInstructionsOrLink = (TextView) findViewById(R.id.instructionsOrLink);

    Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);

    Session session = Session.getActiveSession();
    if (session == null) {
        if (savedInstanceState != null) {
            session = Session.restoreSession(this, null, statusCallback, savedInstanceState);
        }
        if (session == null) {
            session = new Session(this);
        }
        Session.setActiveSession(session);
        if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
            session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
        }
    }
    Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(this,
            Arrays.asList("friends_birthday"));
    session.requestNewReadPermissions(newPermissionsRequest);
    updateView();
}

From source file:com.connectsdk.service.config.WebOSTVServiceConfig.java

private String exportCertificateToPEM(X509Certificate cert) {
    try {//from   ww w  .ja  v  a  2  s.co  m
        if (cert == null)
            return null;
        return Base64.encodeToString(cert.getEncoded(), Base64.DEFAULT);
    } catch (CertificateEncodingException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.ibm.pickmeup.utils.MessageConductor.java

/**
 * Steer the message according to the rules related to the message payload and topic
 *
 * @param payload as a String//  w w w  .  j a  v  a  2s .  co m
 * @param topic   as a String
 * @throws JSONException
 */
public void steerMessage(String payload, String topic) throws JSONException {
    Log.d(TAG, ".steerMessage() entered");

    // create a JSONObject from the payload string
    JSONObject jsonPayload = new JSONObject(payload);

    if (jsonPayload.has(Constants.TYPE) && jsonPayload.has(Constants.DRIVER_ID)
            && jsonPayload.get(Constants.TYPE).equals(Constants.ACCEPT)) {

        // pairing message - get the driverId and send it to the router
        String driverId = jsonPayload.getString(Constants.DRIVER_ID);
        Intent actionIntent = new Intent(Constants.ACTION_INTENT_ROUTE_MESSAGE);
        actionIntent.putExtra(Constants.ROUTE_MESSAGE_TYPE, Constants.ACTION_INTENT_DRIVER_ACCEPTED);
        actionIntent.putExtra(Constants.DRIVER_ID, driverId);
        context.sendBroadcast(actionIntent);
    } else if (topic.contains(Constants.PICTURE) && jsonPayload.has(Constants.URL)) {

        // driver picture message - get the driverPicture as bytes array and send it to the router
        String urlStr = jsonPayload.getString(Constants.URL);
        byte[] decodedPictureAsBytes = Base64.decode(urlStr.substring(urlStr.indexOf(",")), Base64.DEFAULT);
        Intent actionIntent = new Intent(Constants.ACTION_INTENT_ROUTE_MESSAGE);
        actionIntent.putExtra(Constants.ROUTE_MESSAGE_TYPE, Constants.ACTION_INTENT_DRIVER_DETAILS_RECEIVED);
        actionIntent.putExtra(Constants.DRIVER_PICTURE, decodedPictureAsBytes);
        context.sendBroadcast(actionIntent);
    } else if (topic.contains(Constants.DRIVER_HEAD_PREFIX) && jsonPayload.has(Constants.NAME)
            && jsonPayload.has(Constants.CONNECTION_TIME)) {

        // driver name message - get the name and send it to the router
        String driverName = jsonPayload.getString(Constants.NAME);
        Intent actionIntent = new Intent(Constants.ACTION_INTENT_ROUTE_MESSAGE);
        actionIntent.putExtra(Constants.ROUTE_MESSAGE_TYPE, Constants.ACTION_INTENT_DRIVER_DETAILS_RECEIVED);
        actionIntent.putExtra(Constants.NAME, driverName);
        context.sendBroadcast(actionIntent);
    } else if (topic.equals(TopicFactory.getInstance(context).getPassengerChatTopic())
            && jsonPayload.has(Constants.FORMAT) && jsonPayload.has(Constants.DATA)) {

        // chat message - get the format and data and send it to the router
        Intent actionIntent = new Intent(Constants.ACTION_INTENT_ROUTE_MESSAGE);
        actionIntent.putExtra(Constants.ROUTE_MESSAGE_TYPE, Constants.ACTION_INTENT_CHAT_MESSAGE_RECEIVED);
        String format = jsonPayload.getString(Constants.FORMAT);
        String data = jsonPayload.getString(Constants.DATA);
        actionIntent.putExtra(Constants.DATA, data);
        actionIntent.putExtra(Constants.FORMAT, format);
        context.sendBroadcast(actionIntent);
    } else if (topic.equals(TopicFactory.getInstance(context).getDriverLocationTopic())
            && jsonPayload.has(Constants.LATITUDE) && jsonPayload.has(Constants.LONGITUDE)) {

        // driver location message - send it directly to the map
        // check for previousCoordinatesReceivedTime to throttle messages within 100 milliseconds
        if (System.currentTimeMillis() - previousCoordinatesReceivedTime > 100) {
            Intent actionIntent = new Intent(Constants.ACTION_INTENT_COORDINATES_CHANGED);
            float lon = Float.parseFloat(jsonPayload.getString(Constants.LONGITUDE));
            float lat = Float.parseFloat(jsonPayload.getString(Constants.LATITUDE));
            actionIntent.putExtra(Constants.LONGITUDE, lon);
            actionIntent.putExtra(Constants.LATITUDE, lat);
            context.sendBroadcast(actionIntent);
            previousCoordinatesReceivedTime = System.currentTimeMillis();
        }
    } else if (topic.equals(TopicFactory.getInstance(context).getPassengerInboxTopic())
            && jsonPayload.has(Constants.TYPE)) {
        if (jsonPayload.get(Constants.TYPE).equals(Constants.TRIP_START)) {

            // trip started message - send it to the router
            Intent actionIntent = new Intent(Constants.ACTION_INTENT_ROUTE_MESSAGE);
            actionIntent.putExtra(Constants.ROUTE_MESSAGE_TYPE, Constants.ACTION_INTENT_START_TRIP);
            context.sendBroadcast(actionIntent);
        } else if (jsonPayload.get(Constants.TYPE).equals(Constants.TRIP_END) && jsonPayload.has(Constants.TIME)
                && jsonPayload.has(Constants.COST) && jsonPayload.has(Constants.DISTANCE)) {

            // trip ended message - collect time, distance, cost and send to the router
            Intent actionIntent = new Intent(Constants.ACTION_INTENT_ROUTE_MESSAGE);
            actionIntent.putExtra(Constants.ROUTE_MESSAGE_TYPE, Constants.ACTION_INTENT_END_TRIP);
            String time = jsonPayload.getString(Constants.TIME);
            String distance = jsonPayload.getString(Constants.DISTANCE);
            String cost = jsonPayload.getString(Constants.COST);
            actionIntent.putExtra(Constants.TIME, time);
            actionIntent.putExtra(Constants.DISTANCE, distance);
            actionIntent.putExtra(Constants.COST, cost);
            context.sendBroadcast(actionIntent);
        } else if (jsonPayload.get(Constants.TYPE).equals(Constants.TRIP_PROCESSED)) {

            // payment processed message - send it directly to the waiting activity
            Intent actionIntent = new Intent(Constants.ACTION_INTENT_PAYMENT_RECEIVED);
            context.sendBroadcast(actionIntent);
        }
    }
}

From source file:io.realm.RealmJsonTest.java

public void testCreateObjectFromJson_allSimpleObjectAllTypes() throws JSONException {
    JSONObject json = new JSONObject();
    json.put("columnString", "String");
    json.put("columnLong", 1l);
    json.put("columnFloat", 1.23f);
    json.put("columnDouble", 1.23d);
    json.put("columnBoolean", true);
    json.put("columnBinary", new String(Base64.encode(new byte[] { 1, 2, 3 }, Base64.DEFAULT)));

    testRealm.beginTransaction();/* w  w w . j av  a2s  .co m*/
    testRealm.createObjectFromJson(AllTypes.class, json);
    testRealm.commitTransaction();
    AllTypes obj = testRealm.allObjects(AllTypes.class).first();

    // Check that all primitive types are imported correctly
    assertEquals("String", obj.getColumnString());
    assertEquals(1l, obj.getColumnLong());
    assertEquals(1.23f, obj.getColumnFloat());
    assertEquals(1.23d, obj.getColumnDouble());
    assertEquals(true, obj.isColumnBoolean());
    assertArrayEquals(new byte[] { 1, 2, 3 }, obj.getColumnBinary());
}

From source file:de.skubware.opentraining.db.rest.ExerciseImageGSONSerializer.java

@Override
public JsonElement serialize(ExerciseImage ex, Type typeOfSrc, JsonSerializationContext context) {

    JsonObject mainObject = new JsonObject();

    FileInputStream fis = null;/*from  w  ww  .j  a va 2 s.c o m*/
    String imgString = null;

    try {
        fis = new FileInputStream(ex.getRealImagePath());
    } catch (FileNotFoundException e) {
        Log.i(TAG, "File not found: " + ex.getRealImagePath());
        e.printStackTrace();
    }

    Bitmap bm = BitmapFactory.decodeStream(fis);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(CompressFormat.JPEG, 100, baos);
    byte[] imgByte = baos.toByteArray();
    imgString = Base64.encodeToString(imgByte, Base64.DEFAULT);

    Log.i("Minion", "imgString -> JSONObject SUCCESS");
    mainObject.addProperty("image", imgString);

    mainObject.addProperty("license", 3);
    mainObject.addProperty("exercise", 260);

    return mainObject;

}

From source file:com.amazonaws.mobileconnectors.kinesis.kinesisrecorder.internal.JSONRecordAdapter.java

/**
 * @param source The JSONObject that was created and stored via translateFromRecord
 * @return The corresponding// w  w  w. ja v a 2 s .c o m
 */
public PutRecordRequest translateToRecord(JSONObject source) {

    PutRecordRequest putRequest = new PutRecordRequest();
    try {
        putRequest.withData(ByteBuffer.wrap(Base64.decode(source.getString(DATA_FIELD_KEY), Base64.DEFAULT)));
        putRequest.withPartitionKey(source.getString(PARTITION_KEY_FIELD));
        putRequest.withStreamName(source.getString(STREAM_NAME_FIELD));
        if (source.has(EXPLICIT_HASH_FIELD)) {
            putRequest.withExplicitHashKey(source.getString(EXPLICIT_HASH_FIELD));
        }
        if (source.has(SEQUENCE_NUMBER_FIELD)) {
            putRequest.withSequenceNumberForOrdering(source.getString(SEQUENCE_NUMBER_FIELD));
        }

        return putRequest;

    } catch (JSONException e) {
        logger.e("Error creating stored request from representation on disk, ignoring request", e);
        return null;
    }

}