List of usage examples for android.util Log i
public static int i(String tag, String msg)
From source file:app.wz.HttpClient.java
public static String SendHttpPost(String URL, JSONObject jsonObjSend) { try {/* ww w . j a va 2 s . c o m*/ DefaultHttpClient httpclient = new DefaultHttpClient(); HttpPost httpPostRequest = new HttpPost(URL); StringEntity se; se = new StringEntity(jsonObjSend.toString()); // Set HTTP parameters httpPostRequest.setEntity(se); httpPostRequest.setHeader("Accept", "application/json"); httpPostRequest.setHeader("Content-type", "application/json"); httpPostRequest.setHeader("Accept-Encoding", "gzip"); // only set this parameter if you would like to use gzip compression long t = System.currentTimeMillis(); HttpResponse response = (HttpResponse) httpclient.execute(httpPostRequest); Log.i(TAG, "HTTPResponse received in [" + (System.currentTimeMillis() - t) + "ms]"); // Get hold of the response entity (-> the data): HttpEntity entity = response.getEntity(); if (entity != null) { return EntityUtils.toString(entity); // // Read the content stream // InputStream instream = entity.getContent(); // Header contentEncoding = response.getFirstHeader("Content-Encoding"); // if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) { // instream = new GZIPInputStream(instream); // } // // // convert content stream to a String // String resultString= convertStreamToString(instream); // instream.close(); // resultString = resultString.substring(1,resultString.length()-1); // remove wrapping "[" and "]" // // // Transform the String into a JSONObject // JSONObject jsonObjRecv = new JSONObject(resultString); // // Raw DEBUG output of our received JSON object: // Log.i(TAG,"<JSONObject>\n"+jsonObjRecv.toString()+"\n</JSONObject>"); // // return jsonObjRecv; } } catch (Exception e) { // More about HTTP exception handling in another tutorial. // For now we just print the stack trace. e.printStackTrace(); } return null; }
From source file:com.grinnellplans.plandroid.LoginTask.java
protected String doInBackground(String... params) { Log.i("LoginTask::doInBackground", "entered"); AndroidHttpClient plansClient = AndroidHttpClient.newInstance("plandroid"); final HttpPost req = new HttpPost("http://" + _ss.get_serverName() + "/api/1/index.php?task=login"); List<NameValuePair> postParams = new ArrayList<NameValuePair>(2); postParams.add(new BasicNameValuePair("username", params[0])); postParams.add(new BasicNameValuePair("password", params[1])); Log.i("LoginTask::doInBackground", "setting postParams"); String resp = null;/* w w w . ja va 2 s .co m*/ try { req.setEntity(new UrlEncodedFormEntity(postParams)); HttpResponse response = null; Log.i("LoginTask::doInBackground", "executing request"); response = plansClient.execute(req, _httpContext); Log.i("LoginTask::doInBackground", "reading response"); resp = new BufferedReader((new InputStreamReader(response.getEntity().getContent()))).readLine(); } catch (Exception e) { resp = constructResponse(e); } plansClient.close(); Log.i("LoginTask::doInBackground", "server responded \"" + resp + "\""); Log.i("LoginTask::doInBackground", "exit"); return resp; }
From source file:it.nicola_amatucci.util.JsonAndroidLocalIO.java
public static <T> boolean saveData(Context context, String filename, T o, Class<T> obj) { String document = null;/*ww w . j a va 2 s. c o m*/ try { document = Json.json_from_object(o, obj).toString(); if (document != null) { Log.i("TAG", document); FileOutputStream fos = context.openFileOutput(filename, Context.MODE_PRIVATE); fos.write(document.getBytes()); fos.close(); return true; } } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:com.milang.torparknow.GreenParkingApp.java
/** * Load carparks by reading JSON, then populating carparks * @param context//from ww w . j a va2s .co m * @return */ public static ArrayList<Carpark> loadCarparks(Context context) { Log.i(TAG, "Loading JSON"); JSONObject json = GreenParkingApp.readJson(context); Log.i(TAG, "Populating carparksArray"); if (json != null) { try { JSONArray carparksJson = json.getJSONArray("carparks"); for (int i = 0; i < carparksJson.length(); i++) { JSONObject carpark = carparksJson.getJSONObject(i); carparks.add(Carpark.fromJSON(carpark)); } } catch (JSONException e) { e.printStackTrace(); } } Log.i(TAG, "Done populating carparks"); return carparks; }
From source file:MainActivity.java
public void launchIntent(View view) { Log.i("MainActivity", "launchIntent()"); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("https://www.java2s.com/")); startActivity(intent);/*from w w w . j a v a 2 s . c o m*/ }
From source file:Main.java
/** * Log as info the specified {@link MeasureSpec} in a readable manner. * //from ww w.j a v a2 s. c o m * @param tag * the tag for android logging system. * @param message * the starting message of the log. * @param measureSpec * the measure spec to log. */ public static void dumpMeasureSpec(String tag, String message, int measureSpec) { StringBuilder _measureSpec = new StringBuilder(message); _measureSpec.append(" : "); switch (MeasureSpec.getMode(measureSpec)) { case MeasureSpec.AT_MOST: _measureSpec.append("at most "); break; case MeasureSpec.EXACTLY: _measureSpec.append("Exactly "); break; case MeasureSpec.UNSPECIFIED: _measureSpec.append("Unspecified "); break; } _measureSpec.append(MeasureSpec.getSize(measureSpec)); Log.i(tag, _measureSpec.toString()); }
From source file:com.rukiasoft.androidapps.comunioelpuntal.crashlogs.ExceptionHandler.java
public static boolean register(Context _context) { Log.i(TAG, "Registering default exceptions handler"); context = _context;// w w w. j a va 2 s .c o m // Get information about the Package PackageManager pm = context.getPackageManager(); try { PackageInfo pi; // Version pi = pm.getPackageInfo(context.getPackageName(), 0); G.APP_VERSION = pi.versionName; // Package name G.APP_PACKAGE = pi.packageName; // Files dir for storing the stack traces G.FILES_PATH = context.getFilesDir().getAbsolutePath(); // Device model G.PHONE_MODEL = android.os.Build.MODEL; // Android version G.ANDROID_VERSION = android.os.Build.VERSION.RELEASE; } catch (NameNotFoundException e) { e.printStackTrace(); } /*Log.d(TAG, "APP_VERSION: " + G.APP_VERSION); Log.d(TAG, "APP_PACKAGE: " + G.APP_PACKAGE); Log.d(TAG, "FILES_PATH: " + G.FILES_PATH);*/ boolean stackTracesFound = false; // We'll return true if any stack traces were found if (searchForStackTraces().length > 0) { stackTracesFound = true; } new Thread() { @Override public void run() { // First of all transmit any stack traces that may be lying around submitStackTraces(); UncaughtExceptionHandler currentHandler = Thread.getDefaultUncaughtExceptionHandler(); if (currentHandler != null) { Log.d(TAG, "current handler class=" + currentHandler.getClass().getName()); } // don't register again if already registered if (!(currentHandler instanceof DefaultExceptionHandler)) { Log.d(TAG, "Register default exceptions handler"); Thread.setDefaultUncaughtExceptionHandler(new DefaultExceptionHandler(currentHandler)); } } }.start(); return stackTracesFound; }
From source file:uf.edu.AddLocation.java
public static String getLocation(TreeSet<String> APs) { Iterator<String> itr = APs.iterator(); JSONArray wifiaps = new JSONArray(); String out = null;//from www .ja v a 2 s. com //put mac address in the json array while (itr.hasNext()) { JSONObject wifiap = new JSONObject(); try { wifiap.put("mac_address", (String) itr.next()); //TODO: add signal strength } catch (JSONException e) { Log.i(TAG, "AddLocation: Exception" + e.getMessage()); e.printStackTrace(); } wifiaps.put(wifiap); } //Adding rest of the data to create a complete Jason Package JSONObject obj = new JSONObject(); try { obj.put("version", "1.1.0"); obj.put("request_address", true); obj.put("wifi_towers", wifiaps); } catch (JSONException e) { Log.i(TAG, "AddLocation: Exception" + e.getMessage()); } //Now ask the Google Server for address. JSONObject output = SendHttpPost(url, obj); if (output == null) { return null; } //Parse out the address. try { out = ((JSONObject) output.get("location")).get("latitude") + "," + ((JSONObject) output.get("location")).get("longitude"); } catch (Exception e) { Log.i(TAG, "AddLocation: Exception parsing JSON " + e.getMessage()); } try { out = out + "," + ((JSONObject) output.get("location")).get("accuracy"); } catch (Exception e) { Log.i(TAG, "AddLocation: Exception parsing JSON " + e.getMessage()); } /* try{ JSONObject address = ((JSONObject)((JSONObject)output.get("location")).get("address")); try{ out = out +","+ address.get("street_number") + "," + address.get("street")+"," + address.get("postal_code"); } catch (Exception e) { Log.i(TAG,"AddLocation: Exception parsing JSON " + e.getMessage()); } try{ out =out +","+ address.get("city") +","+ address.get("county")+","+ address.get("region")+","+ address.get("country")+","+address.get("country_code") +"\n"; } catch (Exception e) { Log.i(TAG,"AddLocation: Exception parsing JSON " + e.getMessage()); } Iterator<String> it = address.keys(); while(it.hasNext()){ Log.i(TAG,"AddLocation: Key iterator: " + it.next()); } } catch (Exception e) { Log.i(TAG,"AddLocation: Exception parsing JSON " + e.getMessage()); } */ Log.i(TAG, "AddLocation: " + out); return out; }
From source file:Main.java
private static File getExternalCacheDir(Context context, String dirName) { File dataDir = new File(new File(Environment.getExternalStorageDirectory(), "Android"), "data"); File appCacheDir2 = new File(new File(dataDir, context.getPackageName()), "cache"); File appCacheDir = new File(appCacheDir2, dirName); if (!appCacheDir.exists()) { if (!appCacheDir.mkdirs()) { Log.w(TAG, "Unable to create external cache directory"); return null; }//ww w.ja v a 2s.c o m try { new File(appCacheDir, ".nomedia").createNewFile(); } catch (IOException e) { Log.i(TAG, "Can't create \".nomedia\" file in application external cache directory"); } } return appCacheDir; }
From source file:GeofenceIntentService.java
private void sendNotification() { Log.i("GeofenceIntentService", "sendNotification()"); Uri notificationSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Geofence Alert") .setContentText("GEOFENCE_TRANSITION_DWELL").setSound(notificationSoundUri) .setLights(Color.BLUE, 500, 500); NotificationManager notificationManager = (NotificationManager) getApplicationContext() .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notificationBuilder.build()); }