List of usage examples for android.util Log d
public static int d(String tag, String msg)
From source file:Main.java
public static boolean WriteFileFromUrl(String url, String filename) { try {// w ww . j a v a 2 s . c om URL fileUrl = new URL(url); URLConnection connection = fileUrl.openConnection(); InputStream inputStream = new BufferedInputStream(fileUrl.openStream(), 10240); File cacheFile = new File(filename); FileOutputStream outputStream = new FileOutputStream(cacheFile); byte buffer[] = new byte[1024]; int dataSize; int loadedSize = 0; while ((dataSize = inputStream.read(buffer)) != -1) { loadedSize += dataSize; outputStream.write(buffer, 0, dataSize); } outputStream.close(); return true; } catch (Exception e) { Log.d("#StorageHelper Error:", e.toString()); return false; } }
From source file:Main.java
/** * @param context/*from ww w .ja v a 2 s . c om*/ * @return KeyHash * follow facebook developers link to get release key hash * https://developers.facebook.com/docs/android/getting-started#release-key-hash */ public static String getKeyHash(Context context) { PackageInfo packageInfo; String key = null; try { packageInfo = context.getPackageManager().getPackageInfo( context.getApplicationContext().getPackageName(), PackageManager.GET_SIGNATURES); for (Signature signature : packageInfo.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT)); } } catch (PackageManager.NameNotFoundException e1) { } catch (NoSuchAlgorithmException e) { } catch (Exception e) { } return key; }
From source file:Main.java
public static DefaultHttpClient setHttpPostProxyParams(Context context, int connTimeout) { Log.d(TAG, "ctx, connTimeout -- called"); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); //schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443)); HttpParams params = new BasicHttpParams(); /*Log.d(TAG, "----Add Proxy---"); HttpHost proxy = new HttpHost(Constants.PROXY_HOST.trim(), Constants.PROXY_PORT);/*w w w . j a v a 2 s.c o m*/ params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);*/ /*if ((getWifiName(context).trim()).equalsIgnoreCase("secure-impact")) { Log.d(TAG, "----Add Proxy---"); HttpHost proxy = new HttpHost(Constants.PROXY_HOST.trim(), Constants.PROXY_PORT); params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); }*/ params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30); params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(30)); params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpConnectionParams.setConnectionTimeout(params, connTimeout); HttpConnectionParams.setSoTimeout(params, connTimeout); ClientConnectionManager cm = new SingleClientConnManager(params, schemeRegistry); DefaultHttpClient mHttpClient = new DefaultHttpClient(cm, params); return mHttpClient; }
From source file:Main.java
private static void log(String msg) { Log.d(LOG_TAG, "[PhoneUtils] " + msg); }
From source file:Main.java
public static int loadShader(final String strSource, final int iType) { int[] compiled = new int[1]; int iShader = GLES20.glCreateShader(iType); GLES20.glShaderSource(iShader, strSource); GLES20.glCompileShader(iShader);/* w w w . j a v a 2 s .com*/ GLES20.glGetShaderiv(iShader, GLES20.GL_COMPILE_STATUS, compiled, 0); if (compiled[0] == 0) { Log.d("Load Shader Failed", "Compilation\n" + GLES20.glGetShaderInfoLog(iShader)); return 0; } return iShader; }
From source file:Main.java
public static void server2mobile(Context context, String type) { String serverPath = "http://shaunrain.zicp.net/FileUp/QueryServlet?type=" + type; try {//from w ww . j av a 2s . c o m URL url = new URL(serverPath); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(10000); conn.setRequestMethod("GET"); int code = conn.getResponseCode(); Log.d("code", code + ""); if (code == 200) { InputStream is = conn.getInputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); int len = 0; byte[] buffer = new byte[1024]; while ((len = is.read(buffer)) != -1) { baos.write(buffer, 0, len); } is.close(); conn.disconnect(); String result = new String(baos.toByteArray()); String[] results = result.split("[$]"); for (String r : results) { if (r.length() != 0) { URL json = new URL(r); HttpURLConnection con = (HttpURLConnection) json.openConnection(); con.setConnectTimeout(5000); con.setRequestMethod("GET"); int co = con.getResponseCode(); if (co == 200) { File jsonFile; if (r.endsWith("clear.json")) { jsonFile = new File( Environment.getExternalStorageDirectory() + "/traffic_json/clear.json"); } else if (r.endsWith("crowd.json")) { jsonFile = new File( Environment.getExternalStorageDirectory() + "/traffic_json/crowd.json"); } else if (r.endsWith("trouble.json")) { jsonFile = new File( Environment.getExternalStorageDirectory() + "/traffic_json/trouble.json"); } else { jsonFile = new File( Environment.getExternalStorageDirectory() + "/traffic_json/control.json"); } if (jsonFile.exists()) jsonFile.delete(); jsonFile.createNewFile(); try (BufferedReader reader = new BufferedReader( new InputStreamReader(con.getInputStream(), "gb2312")); BufferedWriter writer = new BufferedWriter(new FileWriter(jsonFile));) { String line = null; while ((line = reader.readLine()) != null) { writer.write(line); } } } con.disconnect(); } } } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
/** Create a File for saving an image*/ private static File getOutputMediaFile(String fileName) { // To be safe, you should check that the SDCard is mounted // using Environment.getExternalStorageState() before doing this. File mediaStorageDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "DFCarChecker"); // This location works best if you want the created images to be shared // between applications and persist after your app has been uninstalled. // Create the storage directory if it does not exist if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { Log.d("DFCarChecker", "failed to create directory"); return null; }/*from w w w. ja v a2 s .co m*/ } File mediaFile; mediaFile = new File(mediaStorageDir.getPath() + File.separator + fileName + ".jpg"); return mediaFile; }
From source file:com.cbtec.eliademyutils.EliademyUtils.java
public static String serviceCall(String data, String webService, String token, String serviceClient) { String retval = null;/*from w w w . j a va 2 s .co m*/ Log.d("EliademyUtils", "Service: " + data + " Service: " + webService); try { DefaultHttpClient httpclient = new DefaultHttpClient(); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); if (data.toString().length() > 0) { JSONObject jsObj = new JSONObject(data.toString()); nameValuePairs.addAll(nameValueJson(jsObj, "")); } nameValuePairs.add(new BasicNameValuePair("wstoken", token)); nameValuePairs.add(new BasicNameValuePair("wsfunction", webService)); nameValuePairs.add(new BasicNameValuePair("moodlewsrestformat", "json")); HttpPost httppost = new HttpPost(serviceClient + "/webservice/rest/server.php?"); Log.d("EliademyUtils", nameValuePairs.toString()); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); if (entity != null) { StringBuilder jsonStr = new StringBuilder(); InputStream iStream = entity.getContent(); BufferedReader bufferReader = new BufferedReader(new InputStreamReader(iStream)); String jpart; while ((jpart = bufferReader.readLine()) != null) { jsonStr.append(jpart); } iStream.close(); return jsonStr.toString(); } } catch (Exception e) { Log.e("EliademyUtils", "exception", e); return retval; } return retval; }
From source file:Main.java
/** * Create a File for saving an image or video */// w w w .jav a2 s. c om public static File getOutputMediaFile(int type) { // To be safe, you should check that the SDCard is mounted // using Environment.getExternalStorageState() before doing this. File mediaStorageDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "MyCameraApp"); // This location works best if you want the created images to be shared // between applications and persist after your app has been uninstalled. // Create the storage directory if it does not exist if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { Log.d("MyCameraApp", "failed to create directory"); return null; } } // Create a media file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File mediaFile; if (type == MEDIA_TYPE_IMAGE) { mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg"); } else if (type == MEDIA_TYPE_VIDEO) { mediaFile = new File(mediaStorageDir.getPath() + File.separator + "VID_" + timeStamp + ".mp4"); } else if (type == MEDIA_TYPE_AUDIO) { mediaFile = new File(mediaStorageDir.getPath() + File.separator + "AUD_" + timeStamp + ".mp3"); } else { return null; } return mediaFile; }
From source file:Main.java
public static boolean deleteDirectory(String fileName) { boolean status; SecurityManager checker = new SecurityManager(); if (!fileName.equals("")) { File path = Environment.getExternalStorageDirectory(); File newPath = new File(path.toString() + fileName); checker.checkDelete(newPath.toString()); if (newPath.isDirectory()) { String[] listfile = newPath.list(); // delete all files within the specified directory and then // delete the directory try { for (int i = 0; i < listfile.length; i++) { File deletedFile = new File(newPath.toString() + "/" + listfile[i].toString()); deletedFile.delete(); }//from w w w . j a v a2 s . c om newPath.delete(); Log.d(TAG, "DirectoryManager deleteDirectory" + fileName); status = true; } catch (Exception e) { e.printStackTrace(); status = false; } } else status = false; } else status = false; return status; }