Entradas

Mostrando entradas de 2017
EJECUTAR ESCRIBIR DESDE UN ARCHIVO mysql -u root -p XXX < /var/www/html/kanboard/app/Schema/Sql/mysql.sql XXX es el nombre de la base de datos
OBTENER IMEI DE UN DISPOSITIVO ANDROID final TelephonyManager mngr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); String imei = mngr.getDeviceId() != null ? mngr.getDeviceId() : "000000000000000"; OBTENER MAC ADDRESS DE UN DISPOSITIVO ANDROID WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo wInfo = wifiManager.getConnectionInfo(); String macAddress = wInfo.getMacAddress() != null ? wInfo.getMacAddress().toUpperCase() : ""; OBTENER ID DEL DISPOSITIVO ANDROID final TelephonyManager mngr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); imei = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
OBTENER CONTEXTO (RUTA) function obtenerContexto(){ var contexto; var a = location.pathname.split("/"); if ( a.length > 2 ) { contexto=a[1]; } return contexto; } var ruta = obtenerContexto();
COMPLETAR CON CEROS A LA DERECHA function pad (str, max) {  str = str.toString();  return str.length < max ? pad("0" + str, max) : str; } var f = new Date(); var fecha = pad(f.getDate(), 2) + "/" + pad((f.getMonth() +1), 2) + "/" + f.getFullYear();
REEMPLAZAR CARACTERES CON JAVASCRIPT function replaceAll(text, busca, reemplaza) { if (text === undefined) {    //txt = "x is undefined"; return ""; } else {    //txt = "x is defined"; while (text.toString().indexOf(busca) != -1) text = text.toString().replace(busca,reemplaza); return text; } }
GPS DESACTIVADO public static void alertaGpsDesactivado(final Context context){ final AlertDialog alertDialog = new AlertDialog.Builder(context).create(); alertDialog.setTitle(Constantes.MENSAJE); alertDialog.setMessage(Constantes.MENSAJE_GPS_DESACTIVADO); alertDialog.setIcon(R.drawable.info_48x48); alertDialog.setButton("Aceptar", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { context.startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)); alertDialog.dismiss(); } }); alertDialog.show(); } Util.alertaGpsDesactivado(this);
DISTANCIA ENTRE DOS PUNTOS GEO-REFERENCIADOS public static double distanciaCoord(double lat1, double lng1, double lat2, double lng2) {         //double radioTierra = 3958.75;//en millas         //double radioTierra = 6371;//en kilómetros double radioTierra = 6371000;//en metros         double dLat = Math.toRadians(lat2 - lat1);         double dLng = Math.toRadians(lng2 - lng1);         double sindLat = Math.sin(dLat / 2);         double sindLng = Math.sin(dLng / 2);         double va1 = Math.pow(sindLat, 2) + Math.pow(sindLng, 2) * Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2));         double va2 = 2 * Math.atan2(Math.sqrt(va1), Math.sqrt(1 - va1));         double distancia = radioTierra * va2;            return round(distancia, 8); } public static double round(double value, int places) {    if (places < 0) throw new IllegalArgumentException();    BigDecimal bd = new BigDecimal(value);    bd = bd.setScale(places, RoundingMode.HALF_UP);
MANEJO DE IMAGENES EN ANDROID public static String bitmapToBase64(Bitmap bitmap) {     ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();     bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);     byte[] byteArray = byteArrayOutputStream .toByteArray();     return Base64.encodeToString(byteArray, Base64.DEFAULT); } public static Bitmap base64ToBitmap(String b64) {     byte[] imageAsBytes = Base64.decode(b64.getBytes(), Base64.DEFAULT);     return BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length); }
REEMPLAZAR CARACTERES ESPECIALES public static String reemplazarCarateresEspeciales(String cadena){ //String cadena1 = "Sé te n°ota que est|as eno'jado N° 1234"; String valor = cadena != null ? cadena : ""; valor = valor.replaceAll("[á|à|Á|À]", "A"); valor = valor.replaceAll("[é|è|É|È]", "E"); valor = valor.replaceAll("[í|ì|Í|Ì]", "I"); valor = valor.replaceAll("[ó|ò|Ó|Ò]", "O"); valor = valor.replaceAll("[ú|ù|Ú|Ù]", "U"); valor = valor.replaceAll("[ñ|Ñ]", "N"); //valor = valor.replaceAll("['|||°]", ""); valor = valor.replaceAll("[^-a-zA-Z0-9$ ]+",""); //System.out.println("cadena : " + cadena2); return valor; }
REDIMENSIONAR IMAGENES public static Bitmap redimensionarImagenMaximo(Bitmap mBitmap, String usuario, String imei){ try{ //Redimensionamos int width = mBitmap.getWidth(); int height = mBitmap.getHeight(); float scaleWidth = ((float) Constantes.RESOLUCION_VGA_WIDTH) / width; float scaleHeight = ((float) Constantes.RESOLUCION_VGA_HEIGHT) / height; // create a matrix for the manipulation Matrix matrix = new Matrix(); // resize the bit map matrix.postScale(scaleWidth, scaleHeight); // recreate the new Bitmap return Bitmap.createBitmap(mBitmap, 0, 0, width, height, matrix, false); }catch(Exception e){ LogCustom.error(Util.class.getClass().getName(), usuario, imei, e); return null; } } public static final int RESOLUCION_VGA_WIDTH = 640; public static final int RESOLUCION_VGA_HEIGHT = 480;
OBTENER FECHA Y HORA DEL GPS public static String fechaHoraGPS(Long time) { String fechaHora = ""; GregorianCalendar gcal = new //GregorianCalendar(TimeZone.getTimeZone("UTC"));     GregorianCalendar(TimeZone.getTimeZone("America/Lima"));     gcal.setTimeInMillis(time);         String dia = StringUtils.leftPad(String.valueOf(gcal.get(GregorianCalendar.DAY_OF_MONTH)), 2, "0");     String mes = StringUtils.leftPad(String.valueOf(gcal.get(GregorianCalendar.MONTH) + 1), 2, "0");     String anio = String.valueOf(gcal.get(GregorianCalendar.YEAR));     String hora = StringUtils.leftPad(String.valueOf(gcal.get(GregorianCalendar.HOUR_OF_DAY)), 2, "0");     String minuto = StringUtils.leftPad(String.valueOf(gcal.get(GregorianCalendar.MINUTE)), 2, "0");     String segundo = StringUtils.leftPad(String.valueOf(gcal.get(GregorianCalendar.SECOND)), 2, "0");         fechaHora = dia + "/&
OBTENER FECHA Y HORA public static String obtenerFechaHora(){ Date date = new Date(); //Caso 1: obtener la hora y salida por pantalla con formato: DateFormat hourFormat = new SimpleDateFormat("HH:mm:ss"); //System.out.println("Hora: "+hourFormat.format(date)); //Caso 2: obtener la fecha y salida por pantalla con formato: DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); //System.out.println("Fecha: "+dateFormat.format(date)); //Caso 3: obtenerhora y fecha y salida por pantalla con formato: DateFormat hourdateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); //System.out.println("Fecha y Hora : " + hourdateFormat.format(date)); return hourdateFormat.format(date); }
VERIFICA SI EL DISPOSITIVO CUENTA CON INTERNET public static boolean isOnline(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(context.CONNECTIVITY_SERVICE); NetworkInfo netinfo = cm.getActiveNetworkInfo(); if(netinfo != null && netinfo.isConnected()) { return true; } return false; }
OBTENER DISTANCIA ENTRE DOS PUNTOS DE LATITUD Y LONGITUD package com.prueba; public class GeoReferencia { public static double distanciaCoord(double lat1, double lng1, double lat2, double lng2) {         //double radioTierra = 3958.75;//en millas         //double radioTierra = 6371;//en kilómetros double radioTierra = 6371000;//en metros         double dLat = Math.toRadians(lat2 - lat1);         double dLng = Math.toRadians(lng2 - lng1);         double sindLat = Math.sin(dLat / 2);         double sindLng = Math.sin(dLng / 2);         double va1 = Math.pow(sindLat, 2) + Math.pow(sindLng, 2)                 * Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2));         double va2 = 2 * Math.atan2(Math.sqrt(va1), Math.sqrt(1 - va1));         double distancia = radioTierra * va2;           return distancia;     } public static void main(String[] args) { // TODO Auto-generated method stub //1 => LIMA //2 => LONGITUD double lat1 = -12
CONSUMIR SERVICIO WEB REST CON JAVA package com.prueba; import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; public class ConsumirRest { static String urlGet = "http://m.pension.com.pe:8080/RSAyza/"; static URL url = null; static HttpURLConnection con = null; static BufferedReader bufferReader; static String USER_AGENT = "Mozilla/5.0"; public static void main(String[] args) { //consumirRestGet(); consumirRestPost(); } public static void consumirRestGet(){ String str = ""; StringBuffer stringBuffer = new StringBuffer(); try { url = new URL(urlGet + "tipoCondicion.json"); con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); con.connect(); int responseCode = con.get