List of usage examples for android.util Log d
public static int d(String tag, String msg)
From source file:com.moarub.util.ShareMoreUtils.java
public static StringBuilder getResponseString(HttpResponse result) { if (result == null) { return null; }//from www . ja va2 s .c o m StringBuilder builder = new StringBuilder(""); HttpEntity res = result.getEntity(); InputStream is = null; try { is = res.getContent(); } catch (IllegalStateException e) { Log.d("ResponseString", "Response invalid (IllegalStateException) " + e.getMessage()); return builder; } catch (IOException e) { Log.d("ResponseString", "Response invalid (IoException) " + e.getMessage()); return builder; } BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line = null; try { while ((line = br.readLine()) != null) { builder.append(line); } } catch (IOException e) { Log.d("ResponseString", "IOException " + e.getMessage()); return builder; } return builder; }
From source file:Main.java
/** Create a File for saving an image or video specific to an app name */ public static File getOutputMediaFile(int type, String optionalAppName) { // To be safe, you should check that the SDCard is mounted // using Environment.getExternalStorageState() before doing this. String appname = "CameraApp"; if (optionalAppName != null && !optionalAppName.isEmpty()) { appname = optionalAppName;//from w ww. j a v a2 s.c om } File mediaStorageDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), appname); // 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 == MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE) { mediaFile = new File( mediaStorageDir.getPath() + File.separator + "IMG_" + appname + timeStamp + ".jpg"); } else if (type == MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO) { mediaFile = new File( mediaStorageDir.getPath() + File.separator + "VID_" + appname + timeStamp + ".mp4"); } else { return null; } //USAGE: // fileUri = Helpers.getOutputMediaFileUri( // MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE, // Helpers.getApplicationName(this) // ); // create a file to save the image return mediaFile; }
From source file:Main.java
/** * A proxy for Log.d api that kills log messages in release build. It * not recommended to send sensitive information to log output in * shipping apps./* w w w . j a va 2 s. c o m*/ * * @param tag * @param msg */ public static void logd(String tag, String msg) { if (ENABLE_LOG) { Log.d(tag, msg); } }
From source file:Main.java
public static final String[] getBondedDeviceNames() { BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); Set<BluetoothDevice> devices = adapter.getBondedDevices(); String[] names = new String[devices.size()]; int i = 0;//from w ww . j a va 2s. c om for (BluetoothDevice d : devices) { Log.d(TAG, "Found bonded device " + d.getName()); names[i++] = d.getName(); } return names; }
From source file:Main.java
public static JSONObject callService(String url) { InputStream inputStream = null; JSONObject result = null;// w w w. j av a 2 s. c o m try { // create HttpClient HttpClient httpclient = new DefaultHttpClient(); // make GET request to the given URL HttpResponse httpResponse = httpclient.execute(new HttpGet(url)); // receive response as inputStream inputStream = httpResponse.getEntity().getContent(); // convert inputstream to string if (inputStream != null) { String response = convertInputStreamToString(inputStream); //result = new JSONObject(response); } } catch (Exception e) { Log.d("InputStream", e.getLocalizedMessage()); } return result; }
From source file:org.npr.android.news.DownloadDrawable.java
public static Drawable createFromUrl(String url) { InputStream data = null;//from ww w.ja v a2s . c o m Log.d(LOG_TAG, "Starting download"); HttpClient http = new DefaultHttpClient(); HttpGet method = new HttpGet(url); HttpResponse response = null; try { response = http.execute(method); data = response.getEntity().getContent(); } catch (ClientProtocolException e) { Log.e(LOG_TAG, "error downloading", e); } catch (IOException e) { Log.e(LOG_TAG, "error downloading", e); } catch (IllegalStateException e) { Log.e(LOG_TAG, "error downloading", e); } Log.d(LOG_TAG, "Download complete"); return Drawable.createFromStream(data, url); }
From source file:Main.java
public static void setGcmKey(final Context context, final String accountName, final String gcmKey) { SharedPreferences sp = getSharedPreferences(context); sp.edit().putString(makeAccountSpecificPrefKey(accountName, PREFIX_PREF_GCM_KEY), gcmKey).apply(); Log.d("GoogleAcount", "GCM key of account " + accountName + " set to: " + sanitizeGcmKey(gcmKey)); }
From source file:Main.java
public static String openUrl(String url, String method, Bundle params) { if (method.equals("GET")) { url = url + "?" + encodeUrl(params); }//from ww w.ja v a 2s.c om String response = ""; try { Log.d(LOG_TAG, method + " URL: " + url); HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); conn.setRequestProperty("User-Agent", System.getProperties().getProperty("http.agent") + " RenrenAndroidSDK"); if (!method.equals("GET")) { conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.getOutputStream().write(encodeUrl(params).getBytes("UTF-8")); } response = read(conn.getInputStream()); } catch (Exception e) { Log.e(LOG_TAG, e.getMessage()); throw new RuntimeException(e.getMessage(), e); } return response; }
From source file:Main.java
/** * To add hack to .3gp file// w ww . j a va 2 s . c o m * @param url * @return */ public static String getAudioMimeType(String url) { String type = null; String extension = MimeTypeMap.getFileExtensionFromUrl(url); Log.w("KKIM", " Sending File Extension = " + extension); if (extension != null) { if (extension.equalsIgnoreCase("3gp") || extension.equalsIgnoreCase("3gpp")) { if (is3gpFileAudio(url)) { type = "audio/3gpp"; } else { MimeTypeMap mime = MimeTypeMap.getSingleton(); type = mime.getMimeTypeFromExtension(extension); } } else { MimeTypeMap mime = MimeTypeMap.getSingleton(); type = mime.getMimeTypeFromExtension(extension); } if (type.equalsIgnoreCase("application/ogg")) { type = "audio/ogg"; Log.d("KKIM", "Formatting Audio File Type from application/ogg to audio/ogg"); } } return type; }
From source file:Main.java
public static Map<Integer, List> getCityByPid(int id, File file) { String sql = "select cityid,city from city where provinceid= " + id; SQLiteDatabase db = null;//from ww w. j a v a2 s . c o m Cursor c = null; Map<Integer, List> cityData = new HashMap<Integer, List>(); //List cityList = null; try { db = SQLiteDatabase.openOrCreateDatabase(file, null); c = db.rawQuery(sql, null); List cityList1 = new ArrayList(); List cityList2 = new ArrayList(); while (c.moveToNext()) { Map cityMap = new HashMap(); cityMap.put(c.getString(1), c.getInt(0)); cityList1.add(cityMap); cityList2.add(c.getString(1)); } cityData.put(0, cityList1); cityData.put(1, cityList2); } catch (Exception e) { Log.d("WineStock", "getCityByPid:" + e.getMessage()); } finally { if (c != null) { c.close(); } if (db != null) { db.close(); } } return cityData; }