List of usage examples for android.util Base64 DEFAULT
int DEFAULT
To view the source code for android.util Base64 DEFAULT.
Click Source Link
From source file:eu.codeplumbers.cosi.db.models.Contact.java
public Contact(JSONObject contactJson) throws JSONException { if (contactJson.has("n")) setN(contactJson.getString("n")); else//from ww w . ja v a2 s . c o m setN(""); if (contactJson.has("fn")) setFn(contactJson.getString("fn")); else setFn(""); if (contactJson.has("revision")) { setRevision(contactJson.getString("revision")); } else { setRevision(DateUtils.formatDate(new Date().getTime())); } if (contactJson.has("tags") && !contactJson.getString("tags").equalsIgnoreCase("")) { setTags(contactJson.getJSONArray("tags").toString()); } else { setTags(new JSONArray().toString()); } setPhotoBase64(""); setAnniversary(""); if (contactJson.has("deviceId")) { setDeviceId(contactJson.getString("deviceId")); } if (contactJson.has("systemId")) { setSystemId(contactJson.getString("systemId")); } setRemoteId(contactJson.getString("_id")); if (contactJson.has("_attachments")) { JSONObject attachment = contactJson.getJSONObject("_attachments"); setAttachments(attachment.toString()); if (attachment.has("picture")) { JSONObject picture = attachment.getJSONObject("picture"); String attachmentName = new String( Base64.decode(picture.getString("digest").replace("md5-", ""), Base64.DEFAULT)); Log.d("Contact", attachmentName); } } save(); if (contactJson.has("datapoints")) { JSONArray datapoints = contactJson.getJSONArray("datapoints"); for (int i = 0; i < datapoints.length(); i++) { JSONObject datapoint = datapoints.getJSONObject(i); String value = datapoint.getString("value"); ContactDataPoint contactDataPoint = ContactDataPoint.getByValue(this, value); if (contactDataPoint == null && !value.isEmpty()) { contactDataPoint = new ContactDataPoint(); contactDataPoint.setPref(false); contactDataPoint.setType(datapoint.getString("type")); contactDataPoint.setValue(value); contactDataPoint.setName(datapoint.getString("name")); contactDataPoint.setContact(this); contactDataPoint.save(); } } } }
From source file:com.yanzhenjie.nohttp.cache.CacheEntity.java
/** * @return the data. */ public String getDataBase64() { return Base64.encodeToString(data, Base64.DEFAULT); }
From source file:fr.outadev.skinswitch.MojangAccountSkin.java
@Override public void downloadSkinFromSource(Context context) throws HttpRequest.HttpRequestException, IOException { if (getUuid() == null) { return;/*from w w w. ja v a 2 s .c om*/ } //we have to request a file on Mojang's server if we wanna retrieve the player's skin from his UUID. String body = HttpRequest.get(SESSION_API_URL + getUuid()).useCaches(false).body(); if (body == null) { throw new HttpRequest.HttpRequestException(new IOException("Response to get the skin URL was empty.")); } //we're expecting a JSON document that looks like this: /* { ... "properties": [ { "name": "textures", "value": "<base64 string>" } ] } */ try { //trying to reach the properties.value string JSONObject obj = new JSONObject(body); JSONArray properties = obj.getJSONArray("properties"); if (properties != null) { for (int i = 0; i < properties.length(); i++) { if (properties.getJSONObject(i).getString("name").equals("textures")) { //once that string is reached, we have to decode it: it's in base64 String base64info = properties.getJSONObject(i).getString("value"); JSONObject textureInfo = new JSONObject( new String(Base64.decode(base64info, Base64.DEFAULT))); //the decoded string is also a JSON document, so we parse that. should look like this: /* { ... "textures": { "SKIN": { "url": "<player skin URL>" }, ... } } */ //we want to retrieve the textures.SKIN.url string. that's the skin's URL. /FINALLY/. String url = textureInfo.getJSONObject("textures").getJSONObject("SKIN").getString("url"); if (url != null) { //download the skin from the provided URL byte[] response = HttpRequest.get(url).useCaches(true).bytes(); if (response == null) { throw new HttpRequest.HttpRequestException( new IOException("Couldn't download " + this)); } //decode the bitmap and store it Bitmap bmp = BitmapFactory.decodeByteArray(response, 0, response.length); if (bmp != null) { deleteAllCacheFilesFromFilesystem(context); saveRawSkinBitmap(context, bmp); bmp.recycle(); } } } } } } catch (JSONException e) { throw new HttpRequest.HttpRequestException( new IOException("The response from Mojang was invalid. Woops.")); } }
From source file:com.amanmehara.programming.android.adapters.DetailAdapter.java
private String decodeContent(String content) { return new String(Base64.decode(content, Base64.DEFAULT)); }
From source file:edu.stanford.mobisocial.dungbeetle.obj.action.PlayAllAudioAction.java
public void playNextSong() { if (c.isAfterLast()) { c.close();// www .j av a 2s. com alert.dismiss(); return; } try { final JSONObject objData = new JSONObject(c.getString(c.getColumnIndex(DbObject.JSON))); Runnable r = new Runnable() { @Override public void run() { Log.w("PlayAllAudioAction", objData.optString("feedName")); byte bytes[] = Base64.decode(objData.optString(VoiceObj.DATA), Base64.DEFAULT); File file = new File(getTempFilename()); try { OutputStream os = new FileOutputStream(file); BufferedOutputStream bos = new BufferedOutputStream(os); bos.write(bytes, 0, bytes.length); bos.flush(); bos.close(); copyWaveFile(getTempFilename(), getFilename()); deleteTempFile(); mp = new MediaPlayer(); mp.setDataSource(getFilename()); mp.setOnCompletionListener(new OnCompletionListener() { public void onCompletion(MediaPlayer m) { Log.w("PlayAllAudioAction", "finished"); c.moveToNext(); playNextSong(); } }); mp.prepare(); mp.start(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }; if (context instanceof Activity) { ((Activity) context).runOnUiThread(r); } else { r.run(); } } catch (Exception e) { } }
From source file:com.ibm.pickmeup.utils.MessageFactory.java
/** * Method to create a message with the passenger's photo encoded as base64 string * * @return msg string representation of the JSONObject *///w ww. jav a2 s . com public String getPassengerPhotoMessage() { Log.d(TAG, ".getPassengerPhotoMessage() entered"); PickMeUpApplication app = (PickMeUpApplication) context.getApplicationContext(); Bitmap passengerPhoto = app.getPassengerPhoto(); ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream(); passengerPhoto.compress(Bitmap.CompressFormat.PNG, 100, byteOutputStream); String passengerPhotoAsBase64String = Base64.encodeToString(byteOutputStream.toByteArray(), Base64.DEFAULT); JSONObject msg = new JSONObject(); try { msg.put(Constants.URL, Constants.BASE64_PHOTO_PREFIX + passengerPhotoAsBase64String); } catch (JSONException e) { Log.d(TAG, ".getPassengerPhotoMessage() - Exception caught while generating a JSON object", e.getCause()); } return msg.toString(); }
From source file:com.mojio.mojiosdk.networking.MojioRequest.java
public MojioRequest(Context appContext, int method, String url, Class<T> clazz, Bitmap contentBody, Response.Listener<T> listener, Response.ErrorListener errorListener) { super(method, url, errorListener); commonInit(appContext, method, url, clazz, listener, errorListener); ByteArrayOutputStream baos = new ByteArrayOutputStream(); contentBody.compress(Bitmap.CompressFormat.PNG, 100, baos); byte[] b = baos.toByteArray(); String imageEncoded = Base64.encodeToString(b, Base64.DEFAULT); this.imageByteArray = b; this.contentBody = imageEncoded; }
From source file:com.socialapp.eventmanager.LoginActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { userSkippedLogin = savedInstanceState.getBoolean(USER_SKIPPED_LOGIN_KEY); }/*from w w w. ja v a 2 s .c o m*/ try { PackageInfo info = getPackageManager().getPackageInfo("com.socialapp.eventmanager", PackageManager.GET_SIGNATURES); for (Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); String keyHash = Base64.encodeToString(md.digest(), Base64.DEFAULT); Log.d("************* KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT)); } } catch (PackageManager.NameNotFoundException e) { } catch (NoSuchAlgorithmException e) { } FacebookSdk.sdkInitialize(getApplicationContext()); callbackManager = CallbackManager.Factory.create(); accessTokenTracker = new AccessTokenTracker() { @Override protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) { checkAndRedirectOnFBLogin(); if (isResumed) { FragmentManager manager = getSupportFragmentManager(); int backStackSize = manager.getBackStackEntryCount(); for (int i = 0; i < backStackSize; i++) { manager.popBackStack(); } if (currentAccessToken != null) { // showFragment(SELECTION, false); } else { showFragment(SPLASH, true); } } } }; setContentView(R.layout.activity_login); FragmentManager fm = getSupportFragmentManager(); SplashFragment splashFragment = (SplashFragment) fm.findFragmentById(R.id.splashFragment); fragments[SPLASH] = splashFragment; FragmentTransaction transaction = fm.beginTransaction(); // for(int i = 0; i < fragments.length; i++) { transaction.hide(fragments[0]); // } transaction.commit(); splashFragment.setSkipLoginCallback(new SplashFragment.SkipLoginCallback() { @Override public void onSkipLoginPressed() { userSkippedLogin = true; //showFragment(SELECTION, false); } }); accessTokenTracker.startTracking(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); String userLoggedIn = prefs.getString("email", null); if (userLoggedIn != null) { Intent intent = new Intent(this, MainActivity.class); startActivity(intent); } }
From source file:ca.hoogit.garagepi.Camera.CameraFragment.java
private void handleUpdatingCameraFeed(String frame) { if (isAdded()) { Log.v(TAG, "handleUpdatingCameraFeed: Updating image view"); byte[] decoded = Base64.decode(frame, Base64.DEFAULT); Bitmap bitmap = BitmapFactory.decodeByteArray(decoded, 0, decoded.length); Drawable drawable = new BitmapDrawable(getResources(), bitmap); mCameraFeed.setImageDrawable(drawable); }/*from w ww . j av a 2 s.c o m*/ }