List of usage examples for android.util Base64 encodeToString
public static String encodeToString(byte[] input, int flags)
From source file:com.appybite.customer.AllowedHotels.java
private void loadHotelList() { aryHotelList.clear();/* ww w . j a va 2 s. c o m*/ HotelInfo info = new HotelInfo(); info.id = -1; info.hotel_name = "Welcome"; info.hotel_desc = "Welcome"; aryHotelList.add(info); updateHotelList(); if (NetworkUtils.haveInternet(this)) { //. https://www.appyorder.com/pro_version/webservice_smart_app/Department/GetDepartments.php?hotel_id=6759 // http://www.appyorder.com/pro_version/webservice_smart_app/new/getGeoHotels.php?lat=37&long=-122&rad=30000&t=1 // https://www.appyorder.com/pro_version/webservice_smart_app/new/loginBrand.php?email_id=test@test.com&password=123 RequestParams params = new RequestParams(); params.add("email_id", PrefValue.getString(AllowedHotels.this, R.string.pref_customer_email_id)); params.add("password", Base64.encodeToString( PrefValue.getString(AllowedHotels.this, R.string.pref_customer_pwd).getBytes(), Base64.NO_WRAP)); /*Base64.encodeToString(edt_password.getText().toString().getBytes(), Base64.NO_WRAP));*/ /*params.add("email_id", "demo@appybite.com"); params.add("password", Base64.encodeToString("demo".getBytes(), Base64.NO_WRAP));*/ DialogUtils.launchProgress(this, "Please wait while loading Data"); CustomerHttpClient.get("new/loginBrand.php", params, new AsyncHttpResponseHandler() { @Override public void onFinish() { DialogUtils.exitProgress(); super.onFinish(); } @Override public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) { Toast.makeText(AllowedHotels.this, "Connection was lost (" + statusCode + ")", Toast.LENGTH_LONG).show(); super.onFailure(statusCode, headers, errorResponse, e); } @Override public void onSuccess(int statusCode, Header[] headers, byte[] response) { // Pull out the first event on the public timeline try { String result = new String(response); result.replace("\n", ""); result = result.substring(result.indexOf("{"), result.lastIndexOf("}") + 1); Log.i("HTTP Response <<<", result); JSONObject jsonObject = (JSONObject) new JSONObject(result); String status = jsonObject.getString("status"); if (status.equalsIgnoreCase("true")) { JSONObject jsonAllowed = jsonObject.getJSONObject("allowed hotel list"); String isExistAllowed = (String) jsonAllowed.getString("status"); if (isExistAllowed.equalsIgnoreCase("true")) { JSONObject hotels = jsonAllowed.getJSONObject("hotels"); JSONArray hotelProArray = hotels.getJSONArray("pro"); for (int i = 0; i < hotelProArray.length(); i++) { HotelInfo item = new HotelInfo(); JSONObject object = hotelProArray.getJSONObject(i); item.id = 2; item.hotel_id = object.getInt("id"); item.hotel_desc = object.getString("hotel_desc"); item.hotel_logo = object.getString("hotel_logo"); item.hotel_name = object.getString("hotel_name"); item.hotel_bg = object.getString("hotel_background"); item.license = object.getString("pro"); aryHotelList.add(item); } JSONArray hotelDemoArray = hotels.getJSONArray("demo"); for (int i = 0; i < hotelDemoArray.length(); i++) { HotelInfo item = new HotelInfo(); JSONObject object = hotelDemoArray.getJSONObject(i); item.id = 2; item.hotel_id = object.getInt("id"); item.hotel_desc = object.getString("hotel_desc"); item.hotel_logo = object.getString("hotel_logo"); item.hotel_name = object.getString("hotel_name"); item.hotel_bg = object.getString("hotel_background"); item.license = object.getString("demo"); aryHotelList.add(item); } } else { Toast.makeText(AllowedHotels.this, jsonAllowed.getString("message"), Toast.LENGTH_LONG).show(); } } PrefValue.setString(AllowedHotels.this, R.string.pref_hotel_logo, "welcome"); PrefValue.setString(AllowedHotels.this, R.string.pref_hotel_bg, "welcome"); PrefValue.setString(AllowedHotels.this, R.string.pref_hotel_first, "welcome"); PrefValue.setString(AllowedHotels.this, R.string.pref_hotel_name, "AppyBite World!"); if (DeviceUtil.isTabletByRes(AllowedHotels.this)) { ImageLoader.getInstance().displayImage( PrefValue.getString(AllowedHotels.this, R.string.pref_hotel_bg), ivHotelBg, optionsForBg, animateFirstListener); ImageLoader.getInstance().displayImage( PrefValue.getString(AllowedHotels.this, R.string.pref_hotel_logo), ivHotelLogo, null, animateFirstListener); tvHotelName.setText(PrefValue.getString(AllowedHotels.this, R.string.pref_hotel_name)); } else { if (m_Fragment != null && m_Fragment.getClass().getName() == HotelHomeFragment.class.getName()) ((HotelHomeFragment) m_Fragment).loadHotelInfo(); } updateHotelList(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); Toast.makeText(AllowedHotels.this, "Invalid Data", Toast.LENGTH_LONG).show(); } } }); } else { Toast.makeText(AllowedHotels.this, "No Internet Connection", Toast.LENGTH_LONG).show(); } }
From source file:com.idean.atthack.network.RequestHelper.java
private void setBasicAuth(HttpURLConnection conn) { String auth = Pref.USERNAME.get(mContext) + ":" + Pref.PIN.get(mContext); String encoded = Base64.encodeToString(auth.getBytes(), Base64.DEFAULT); conn.setRequestProperty("Authorization", "Basic " + encoded); conn.setRequestProperty("APIKey", "random1234"); }
From source file:com.towson.wavyleaf.Sighting.java
protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == EDIT_REQUEST && resultCode == RESULT_OK) { editedCoordinatesInOtherActivitySoDontGetGPSLocation = true; Location fixedLocation = data.getExtras().getParcelable("location"); // Current marker is expired, remove that crap mMap.clear();/*from w w w . j a v a 2 s . com*/ mapHasMarker = !mapHasMarker; setUpMapIfNeeded(); updateUILocation(fixedLocation); // Update location to be send with JSON sighting currentEditableLocation.setLatitude(fixedLocation.getLatitude()); currentEditableLocation.setLongitude(fixedLocation.getLongitude()); // Since user edited their coordinates, they obviously know it's right cb.setChecked(true); Toast.makeText(getApplicationContext(), "New position set", Toast.LENGTH_SHORT).show(); } // http://stackoverflow.com/a/15432979/1097170 else if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) { // Set global string (_64bitencoding) immediately Bitmap bm = (Bitmap) data.getExtras().get("data"); ib.setImageBitmap(bm); // Encode _64BitEncoding = Base64.encodeToString(encodeInBase64(bm), Base64.DEFAULT); // Toast.makeText(getApplicationContext(), _64BitEncoding, Toast.LENGTH_SHORT).show(); } //else if (requestCode == GALLERY_REQUEST && resultCode == RESULT_OK) { // Uri selectedImage = data.getData(); // InputStream imageStream = null; // // try { // imageStream = getContentResolver().openInputStream(selectedImage); // } catch (FileNotFoundException e) {} // // Bitmap img = BitmapFactory.decodeStream(imageStream); // ib.setImageBitmap(img); }
From source file:com.appfirst.communication.AFClient.java
/** * Make a HttpPut request and update the content. * // w w w . j av a 2s .com * @param request * a HttpPut request contains the content to be updated. * @return the updated content in JSONObject format, null if query failed. */ private JSONObject makeJsonObjectPutRequest(HttpPut request) { JSONObject jsonObject = null; this.mEncodedAuthString = String.format("Basic %s", Base64.encodeToString(this.mAuthString, Base64.DEFAULT).trim()); request.setHeader(this.mAuthName, this.mEncodedAuthString); try { HttpResponse response = this.mClient.execute(request); if (!Helper.checkStatus(response)) { android.util.Log.e(TAG, String.format("Request failed with :%s", response.getStatusLine())); return null; } HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); String result = Helper.convertStreamToString(instream); jsonObject = new JSONObject(result); instream.close(); } } catch (ClientProtocolException cpe) { cpe.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } catch (JSONException je) { je.printStackTrace(); } return jsonObject; }
From source file:com.tenmiles.helpstack.gears.HSDeskGear.java
private void uploadAttachmentToServer(String cancelTag, String caseId, HSUploadAttachment attachmentObject, RequestQueue queue, Response.Listener<JSONObject> successListener, Response.ErrorListener errorListener) throws JSONException { Uri.Builder builder = new Uri.Builder(); builder.encodedPath(instanceUrl);/*w w w .j av a 2 s .co m*/ builder.appendEncodedPath(caseId.substring(1)); builder.appendEncodedPath("attachments"); String attachmentUrl = builder.build().toString(); String attachmentFileName = attachmentObject.getAttachment().getFileName() == null ? "picture" : attachmentObject.getAttachment().getFileName(); String attachmentMimeType = attachmentObject.getAttachment().getMime_type(); try { JSONObject attachmentPostObject = new JSONObject(); InputStream input = attachmentObject.generateInputStreamToUpload(); ByteArrayOutputStream output = new ByteArrayOutputStream(); byte[] buffer = new byte[512]; try { int n = 0; while (-1 != (n = input.read(buffer))) { output.write(buffer, 0, n); } } catch (IOException e) { e.printStackTrace(); } attachmentPostObject.put("content", Base64.encodeToString(output.toByteArray(), Base64.DEFAULT)); attachmentPostObject.put("content_type", attachmentMimeType); attachmentPostObject.put("file_name", attachmentFileName); DeskJsonObjectRequest attachmentRequest = new DeskJsonObjectRequest(cancelTag, attachmentUrl, attachmentPostObject, successListener, errorListener); addRequestAndStartQueue(queue, attachmentRequest); // For Attachments } catch (FileNotFoundException e) { errorListener.onErrorResponse(new VolleyError("File not found")); e.printStackTrace(); } }
From source file:com.ved.musicmapapp.LoginAcitivity.java
private void setFbJson(JSONObject jSONObjectme, JSONObject jSONObjectbooks, JSONObject jSONObjectgames, JSONObject jSONObjectmovies, JSONObject jSONObjectmusics) { try {/* ww w . j av a 2 s . com*/ String music = ""; JSONArray musicArray = jSONObjectmusics.getJSONArray("data"); if (musicArray.length() > 0) { music = musicArray.getJSONObject(0).getString("name"); } for (int i = 1; i < musicArray.length(); i++) { music += "," + musicArray.getJSONObject(i).getString("name"); } jSONObjectme.put("music", music); } catch (Exception e) { } try { String movies = ""; JSONArray moviesArray = jSONObjectmovies.getJSONArray("data"); if (moviesArray.length() > 0) { movies = moviesArray.getJSONObject(0).getString("name"); } for (int i = 1; i < moviesArray.length(); i++) { movies += "," + moviesArray.getJSONObject(i).getString("name"); } jSONObjectme.put("movies", movies); } catch (Exception e) { } try { String books = ""; JSONArray booksArray = jSONObjectbooks.getJSONArray("data"); if (booksArray.length() > 0) { books = booksArray.getJSONObject(0).getString("name"); } for (int i = 1; i < booksArray.length(); i++) { books += "," + booksArray.getJSONObject(i).getString("name"); } jSONObjectme.put("books", books); } catch (Exception e) { } try { String games = ""; JSONArray gamesArray = jSONObjectgames.getJSONArray("data"); if (gamesArray.length() > 0) { games = gamesArray.getJSONObject(0).getString("name"); } for (int i = 1; i < gamesArray.length(); i++) { games += "," + gamesArray.getJSONObject(i).getString("name"); } jSONObjectme.put("games", games); } catch (Exception e) { } Log.i("check", "jSONObjectme : /// " + jSONObjectme); try { String data = Base64.encodeToString(jSONObjectme.toString().getBytes(), Base64.DEFAULT); edt.putString("FB_JSON", data); edt.commit(); } catch (Exception e) { e.printStackTrace(); } try { if (pd != null && pd.isShowing()) pd.dismiss(); } catch (Exception ex) { } // Go to home page goToHome(); }
From source file:com.cssn.samplesdk.ShowDataActivity.java
private String SendPicture(String CRMID, String XMLData, byte[] DLPic, byte[] FacePic, byte[] SignPic) { JSONObject param = new JSONObject(); try {/* ww w. j a va2 s . c o m*/ //CRMID As String, DL As String, DLPic As String, DLSignature As String, XMLData As String param.put("CRMID", CRMID); param.put("DL", Base64.encodeToString(DLPic, Base64.DEFAULT)); param.put("DLPic", Base64.encodeToString(FacePic, Base64.DEFAULT)); param.put("DLSignature", Base64.encodeToString(SignPic, Base64.DEFAULT)); param.put("XMLData", XMLData); } catch (JSONException e2) { e2.printStackTrace(); } catch (Exception exc) { exc.printStackTrace(); } JSONObject result = null; try { //result = sendJsonRequest("www.AutosoftAutos.com", 80, "http://www.AutosoftAutos.com/ASN.ashx/greetings2",param); //result = sendJsonRequest("www.AutosoftFinance.com", 443, "https://www.AutosoftFinance.com/OLService/Apps.asmx/GetStartupInfo",param); result = sendJsonRequest(443, "https://www.autosoftfinance.com/olservice/Apps.asmx/UploadDL", param); //result = sendJsonRequest("localhost", 82, "http://localhost:82/ASN.ashx/greetings",param); } catch (ClientProtocolException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } if (result != null) { try { JSONArray A = new JSONArray(result.getString("d")); SharedPreferences mySP = getSharedPreferences(MyPrefs, MODE_PRIVATE); SharedPreferences.Editor edit = mySP.edit(); //edit.clear(); for (int i = 0; i <= A.length(); i++) { JSONObject user = new JSONObject(A.getString(i)); if (user.getString("Name").equals("Success")) { //if value is numeric, that is the CRMID... if not, it is an error return user.getString("Value"); } } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return ""; }
From source file:com.appfirst.communication.AFClient.java
/** * Make a get request and return a JSONArray. * /*www . j ava 2s . c o m*/ * @param getRequest * a HTTPGet request. * @return JSONArray, null if error occurs. */ private JSONArray makeJsonArrayRequest(HttpGet getRequest) { JSONArray jsonArray = null; this.mEncodedAuthString = String.format("Basic %s", Base64.encodeToString(this.mAuthString, Base64.DEFAULT).trim()); getRequest.setHeader(this.mAuthName, this.mEncodedAuthString); try { HttpResponse response = this.mClient.execute(getRequest); if (!Helper.checkStatus(response)) { android.util.Log.e(TAG, String.format("Request failed with :%s", response.getStatusLine())); return null; } HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); String result = Helper.convertStreamToString(instream); jsonArray = new JSONArray(result); instream.close(); } } catch (ClientProtocolException cpe) { cpe.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } catch (JSONException je) { je.printStackTrace(); } return jsonArray; }
From source file:com.ved.musicmapapp.LoginAcitivity.java
private void getFaceAccInfo1(String userid) { if (!pd.isShowing()) pd.show();/*ww w. j a v a 2 s . c om*/ String fqlQuery = "SELECT uid,first_name,last_name,name,email,birthday_date,current_location," + "about_me,sex,religion,languages, music, movies, books,games,work,education, " + "favorite_athletes,inspirational_people,favorite_teams " + "FROM user WHERE uid='" + userid + "'"; Bundle params = new Bundle(); params.putString("q", fqlQuery); params.putString("access_token", ACCESS_TOKEN); Session session = Session.getActiveSession(); Request request = new Request(session, "/fql", params, HttpMethod.GET, new Request.Callback() { public void onCompleted(Response response) { GraphObject graphObject = response.getGraphObject(); JSONObject jsonObject = graphObject.getInnerJSONObject(); try { JSONObject obj = jsonObject.getJSONArray("data").getJSONObject(0) .getJSONObject("current_location"); Toast.makeText(getApplicationContext(), "" + jsonObject.getJSONArray("data"), Toast.LENGTH_LONG) .show(); Log.i("json", jsonObject.getJSONArray("data") + ""); edt.putString("LAST_LONGITUDE", obj.getString("longitude")); edt.putString("LAST_LATITUDE", obj.getString("latitude")); Log.i("JSON_DATA", jsonObject.toString()); edt.commit(); } catch (JSONException e) { e.printStackTrace(); } // try { String data = Base64.encodeToString(jsonObject.toString().getBytes(), Base64.DEFAULT); edt.putString("FB_JSON", data); edt.commit(); } catch (Exception e) { e.printStackTrace(); } pd.dismiss(); // Go to home page goToHome(); } }); Request.executeBatchAsync(request); }
From source file:com.appfirst.communication.AFClient.java
/** * Make a get request and return a JSONObject; * /*from w w w . j a va 2s . c o m*/ * @param jsonObject * a HttpGet request. * @return JSONObject, null if error occurs. */ private JSONObject makeJsonObjectRequest(HttpGet getRequest) { JSONObject jsonObject = null; this.mEncodedAuthString = String.format("Basic %s", Base64.encodeToString(this.mAuthString, Base64.DEFAULT).trim()); getRequest.setHeader(this.mAuthName, this.mEncodedAuthString); try { HttpResponse response = this.mClient.execute(getRequest); if (!Helper.checkStatus(response)) { android.util.Log.e(TAG, String.format("Request failed with :%s", response.getStatusLine())); return null; } HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); String result = Helper.convertStreamToString(instream); jsonObject = new JSONObject(result); instream.close(); } } catch (ClientProtocolException cpe) { cpe.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } catch (JSONException je) { je.printStackTrace(); } return jsonObject; }