List of usage examples for android.util Log getStackTraceString
public static String getStackTraceString(Throwable tr)
From source file:de.mango.business.GoogleSearchProvider.java
public Vector<String> search(String query, int count, int page) { Vector<String> results = new Vector<String>(); // Prepare the query try {//from www. ja va2 s. c om query = "http://ajax.googleapis.com/ajax/services/search/images?" + GoogleSearchProvider.searchArguments + this.hostLanguage + "&q=" + URLEncoder.encode( GoogleSearchProvider.restrictToOpenClipart ? query + GoogleSearchProvider.openClipart : query, "UTF-8") + "&start="; } catch (UnsupportedEncodingException e) { if (DEBUG) { Log.w(TAG, "Unsupported Encoding Exception:" + e.getMessage()); Log.w(TAG, Log.getStackTraceString(e)); } return results; } // start argument to pass to google int firstindex = count * page; // count of results to skip before adding them to the result array int skip = 0; // start indices > 56 are skipped by Google, so we // ask for results from 56, but skip the unwanted $skip indices if (firstindex > 63) return results; if (firstindex > 56) { skip = firstindex - 56; firstindex = 56; } boolean readMore = true; // do we need more queries and are they // possible? while (readMore) { // add start index to the query String currentQuery = query + firstindex; if (DEBUG) Log.d(TAG, "Searching: " + currentQuery); try { // prepare the connection URL url = new URL(currentQuery); URLConnection connection = url.openConnection(); connection.addRequestProperty("Referer", GoogleSearchProvider.refererUrl); connection.setConnectTimeout(2000); connection.setReadTimeout(2000); connection.connect(); // receive the results StringBuilder builder = new StringBuilder(); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line; while ((line = reader.readLine()) != null) { builder.append(line); } // parse the results JSONObject json = new JSONObject(builder.toString()); int responseStatus = json.getInt("responseStatus"); if (responseStatus == 200)// successful search { json = json.getJSONObject("responseData"); JSONArray res = json.getJSONArray("results"); if (res.length() == 0) return results; String s; int limit = Math.min(res.length(), count - results.size() + skip); for (int i = skip; i < limit; i++) { s = res.getJSONObject(i).getString("unescapedUrl"); if (s != null) results.addElement(s); } // see if there are "more Results" JSONObject cursor = json.getJSONObject("cursor"); JSONArray pages = cursor.getJSONArray("pages"); int pageCount = pages.length(); int currentPageIndex = cursor.getInt("currentPageIndex"); this.moreResults = readMore = (pageCount - 1) > currentPageIndex; } else { if (DEBUG) Log.w(TAG, "Goole Search Error (Code " + responseStatus + "):" + json.getString("responseDetails")); this.moreResults = readMore = false;// prevent for (;;) loop // on errors } } catch (MalformedURLException e) { if (DEBUG) { Log.w(TAG, "MalformedURLException:" + e.getMessage()); Log.w(TAG, Log.getStackTraceString(e)); } this.moreResults = readMore = false; } catch (IOException e) { if (DEBUG) { Log.w(TAG, "IOException:" + e.getMessage()); Log.w(TAG, Log.getStackTraceString(e)); } this.moreResults = readMore = false; } catch (JSONException e) { if (DEBUG) { Log.w(TAG, "JSONException:" + e.getMessage()); Log.w(TAG, Log.getStackTraceString(e)); } this.moreResults = readMore = false; } // read more only if we can read more AND want to have more readMore = readMore && results.size() < count; if (readMore) { firstindex += 8; if (firstindex > 56)// the last pages always need to start // querying at index 56 (or google returns // errors) { skip = firstindex - 56; firstindex = 56; } } } return results; }
From source file:com.activiti.android.platform.intent.IntentUtils.java
public static boolean actionSendFeedbackEmail(Fragment fr) { try {/*from w w w . ja va 2s. c o m*/ ShareCompat.IntentBuilder iBuilder = ShareCompat.IntentBuilder.from(fr.getActivity()); Context context = fr.getContext(); // Email iBuilder.addEmailTo(context.getResources().getStringArray(R.array.bugreport_email)); // Prepare Subject String versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; int versionCode = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode; String subject = "Alfresco Activiti Android Feedback"; iBuilder.setSubject(subject); // Content DisplayMetrics dm = context.getResources().getDisplayMetrics(); String densityBucket = getDensityString(dm); Map<String, String> info = new LinkedHashMap<>(); info.put("Version", versionName); info.put("Version code", Integer.toString(versionCode)); info.put("Make", Build.MANUFACTURER); info.put("Model", Build.MODEL); info.put("Resolution", dm.heightPixels + "x" + dm.widthPixels); info.put("Density", dm.densityDpi + "dpi (" + densityBucket + ")"); info.put("Release", Build.VERSION.RELEASE); info.put("API", String.valueOf(Build.VERSION.SDK_INT)); info.put("Language", context.getResources().getConfiguration().locale.getDisplayLanguage()); StringBuilder builder = new StringBuilder(); builder.append("\n\n\n\n"); builder.append("Alfresco Activiti Mobile and device details\n"); builder.append("-------------------\n").toString(); for (Map.Entry entry : info.entrySet()) { builder.append(entry.getKey()).append(": ").append(entry.getValue()).append('\n'); } builder.append("-------------------\n\n").toString(); iBuilder.setType("message/rfc822"); iBuilder.setText(builder.toString()); iBuilder.setChooserTitle(fr.getString(R.string.settings_feedback_email)).startChooser(); return true; } catch (Exception e) { Log.d("Action Send Feedback", Log.getStackTraceString(e)); } return false; }
From source file:eu.faircode.netguard.ServiceExternal.java
@Override protected void onHandleIntent(Intent intent) { try {/*from w w w . j a v a2 s . c o m*/ startForeground(ServiceSinkhole.NOTIFY_EXTERNAL, getForegroundNotification(this)); Log.i(TAG, "Received " + intent); Util.logExtras(intent); if (ACTION_DOWNLOAD_HOSTS_FILE.equals(intent.getAction())) { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); String hosts_url = prefs.getString("hosts_url", null); File tmp = new File(getFilesDir(), "hosts.tmp"); File hosts = new File(getFilesDir(), "hosts.txt"); InputStream in = null; OutputStream out = null; URLConnection connection = null; try { URL url = new URL(hosts_url); connection = url.openConnection(); connection.connect(); if (connection instanceof HttpURLConnection) { HttpURLConnection httpConnection = (HttpURLConnection) connection; if (httpConnection.getResponseCode() != HttpURLConnection.HTTP_OK) throw new IOException( httpConnection.getResponseCode() + " " + httpConnection.getResponseMessage()); } int contentLength = connection.getContentLength(); Log.i(TAG, "Content length=" + contentLength); in = connection.getInputStream(); out = new FileOutputStream(tmp); long size = 0; byte buffer[] = new byte[4096]; int bytes; while ((bytes = in.read(buffer)) != -1) { out.write(buffer, 0, bytes); size += bytes; } Log.i(TAG, "Downloaded size=" + size); if (hosts.exists()) hosts.delete(); tmp.renameTo(hosts); String last = SimpleDateFormat.getDateTimeInstance().format(new Date().getTime()); prefs.edit().putString("hosts_last_download", last).apply(); ServiceSinkhole.reload("hosts file download", this, false); } catch (Throwable ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); if (tmp.exists()) tmp.delete(); } finally { try { if (out != null) out.close(); } catch (IOException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } try { if (in != null) in.close(); } catch (IOException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } if (connection instanceof HttpURLConnection) ((HttpURLConnection) connection).disconnect(); } } } finally { stopForeground(true); } }
From source file:com.yasiradnan.Schedule.ScheduleMainActivity.java
private void getJsonData() { try {//from w w w .j ava2 s .co m InputStream inStream = this.getResources().openRawResource(R.raw.program); JSONArray jsonArray = JSONReader.parseStream(inStream); totalPages = jsonArray.length(); data = new ScheduleItem[totalPages][]; for (int counter = 0; counter < jsonArray.length(); counter++) { JSONObject jsonObject = jsonArray.getJSONObject(counter); String getDate = jsonObject.getString("date"); JSONArray getFirstArray = new JSONArray(jsonObject.getString("events")); int itemsCount = getFirstArray.length(); ArrayList<ScheduleItem> items = new ArrayList<ScheduleItem>(); for (int i = 0; i < itemsCount; i++) { JSONObject getJSonObj = (JSONObject) getFirstArray.get(i); String time = getJSonObj.getString("time"); String title = getJSonObj.getString("title"); int typeId = getJSonObj.getInt("type_id"); items.add(new ScheduleItem(time, title, typeId, getDate)); /* a session entry contains multiple sub events */ if (typeId == 0) { JSONArray getEventsArray = new JSONArray(getJSonObj.getString("events")); for (int j = 0; j < getEventsArray.length(); j++) { JSONObject getJSonEventobj = (JSONObject) getEventsArray.get(j); int typeEventId = getJSonEventobj.getInt("type_id"); if (typeEventId == 1) { String EventInfo = getJSonEventobj.getString("info"); String EventTitle = getJSonEventobj.getString("title"); String Eventtime = getJSonEventobj.getString("time"); items.add(new ScheduleItem(Eventtime, EventTitle, EventInfo, typeEventId, getDate)); } else { String EventTitle = getJSonEventobj.getString("title"); String Eventtime = getJSonEventobj.getString("time"); items.add(new ScheduleItem(Eventtime, EventTitle, typeEventId, getDate)); } } } } data[counter] = items.toArray(new ScheduleItem[0]); } } catch (Exception e) { // TODO: handle exception Log.getStackTraceString(e); } }
From source file:com.dm.wallpaper.board.fragments.dialogs.LicensesFragment.java
private void loadLicenses() { mLoadLicenses = new AsyncTask<Void, Void, Boolean>() { StringBuilder sb;// w w w. ja va 2 s . c o m @Override protected void onPreExecute() { super.onPreExecute(); sb = new StringBuilder(); } @Override protected Boolean doInBackground(Void... voids) { while (!isCancelled()) { try { Thread.sleep(1); InputStream rawResource = getActivity().getResources().openRawResource(R.raw.licenses); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(rawResource)); String line; while ((line = bufferedReader.readLine()) != null) { sb.append(line); sb.append("\n"); } bufferedReader.close(); return true; } catch (Exception e) { LogUtil.e(Log.getStackTraceString(e)); return false; } } return false; } @Override protected void onPostExecute(Boolean aBoolean) { super.onPostExecute(aBoolean); if (aBoolean) { mWebView.setVisibility(View.VISIBLE); mWebView.loadDataWithBaseURL(null, sb.toString(), "text/html", "utf-8", null); LocaleHelper.setLocale(getActivity()); } mLoadLicenses = null; } }.execute(); }
From source file:io.teak.sdk.GooglePlay.java
public void init(Context context) { mContext = context;//from w ww . j a v a 2s .c o m mServiceConn = new ServiceConnection() { @Override public void onServiceDisconnected(ComponentName name) { if (Teak.isDebug) { Log.d(LOG_TAG, "Google Play Billing service disconnected."); } mService = null; } @Override public void onServiceConnected(ComponentName name, IBinder service) { if (mDisposed) return; if (Teak.isDebug) { Log.d(LOG_TAG, "Google Play Billing service connected."); } try { Class<?> cls = Class.forName("com.android.vending.billing.IInAppBillingService$Stub"); Method m = cls.getMethod("asInterface", IBinder.class); mService = m.invoke(null, (Object) service); } catch (Exception e) { Log.e(LOG_TAG, "Unable to use 'IInAppBillingService' via reflection. " + Log.getStackTraceString(e)); Teak.sdkRaven.reportException(e); return; } String packageName = mContext.getPackageName(); try { if (Teak.isDebug) { Log.d(LOG_TAG, "Checking for Google Play in-app billing 3 support."); } // check for in-app billing v3 support Class<?> cls = Class.forName("com.android.vending.billing.IInAppBillingService"); Method m = cls.getMethod("isBillingSupported", int.class, String.class, String.class); int response = (Integer) m.invoke(mService, 3, packageName, ITEM_TYPE_INAPP); if (response != BILLING_RESPONSE_RESULT_OK) { Log.e(LOG_TAG, "Error checking for Google Play billing v3 support."); } else { if (Teak.isDebug) { Log.d(LOG_TAG, "Google Play In-app billing version 3 supported for " + packageName); } } // Check for v5 subscriptions support. This is needed for // getBuyIntentToReplaceSku which allows for subscription update response = (Integer) m.invoke(mService, 5, packageName, ITEM_TYPE_SUBS); if (response == BILLING_RESPONSE_RESULT_OK) { if (Teak.isDebug) { Log.d(LOG_TAG, "Google Play Subscription re-signup available."); Log.d(LOG_TAG, "Google Play Subscriptions available."); } } else { if (Teak.isDebug) { Log.d(LOG_TAG, "Google Play Subscription re-signup not available."); } // check for v3 subscriptions support response = (Integer) m.invoke(mService, 3, packageName, ITEM_TYPE_SUBS); if (response == BILLING_RESPONSE_RESULT_OK) { if (Teak.isDebug) { Log.d(LOG_TAG, "Google Play Subscriptions available."); } } else { if (Teak.isDebug) { Log.d(LOG_TAG, "Google Play Subscriptions NOT available. Response: " + response); } } } } catch (Exception e) { Log.e(LOG_TAG, "Error working with InAppBillingService: " + Log.getStackTraceString(e)); Teak.sdkRaven.reportException(e); } } }; Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND"); serviceIntent.setPackage("com.android.vending"); List<ResolveInfo> intentServices = mContext.getPackageManager().queryIntentServices(serviceIntent, 0); if (intentServices != null && !intentServices.isEmpty()) { mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE); } else { Log.e(LOG_TAG, "Google Play Billing service unavailable on device."); } }
From source file:com.master.metehan.filtereagle.AdapterLog.java
public AdapterLog(Context context, Cursor cursor, boolean resolve, boolean organization) { super(context, cursor, 0); this.resolve = resolve; this.organization = organization; colID = cursor.getColumnIndex("ID"); colTime = cursor.getColumnIndex("time"); colVersion = cursor.getColumnIndex("version"); colProtocol = cursor.getColumnIndex("protocol"); colFlags = cursor.getColumnIndex("flags"); colSAddr = cursor.getColumnIndex("saddr"); colSPort = cursor.getColumnIndex("sport"); colDAddr = cursor.getColumnIndex("daddr"); colDPort = cursor.getColumnIndex("dport"); colDName = cursor.getColumnIndex("dname"); colUid = cursor.getColumnIndex("uid"); colData = cursor.getColumnIndex("data"); colAllowed = cursor.getColumnIndex("allowed"); colConnection = cursor.getColumnIndex("connection"); colInteractive = cursor.getColumnIndex("interactive"); TypedValue tv = new TypedValue(); context.getTheme().resolveAttribute(R.attr.colorOn, tv, true); colorOn = tv.data;/*from www. jav a 2 s.co m*/ context.getTheme().resolveAttribute(R.attr.colorOff, tv, true); colorOff = tv.data; iconSize = Util.dips2pixels(24, context); try { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); dns = ServiceSinkhole.getDns(context).get(0); vpn4 = InetAddress.getByName(prefs.getString("vpn4", "10.1.10.1")); vpn6 = InetAddress.getByName(prefs.getString("vpn6", "fd00:1:fd00:1:fd00:1:fd00:1")); } catch (UnknownHostException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } }
From source file:net.olejon.mdapp.MyTools.java
public int getProjectVersionCode() { int code = 0; try {//from w w w . j a v a2 s .c om code = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0).versionCode; } catch (Exception e) { Log.e("MyTools", Log.getStackTraceString(e)); } return code; }
From source file:org.catrobat.catroid.ui.dialogs.OrientationDialog.java
protected void handleOkButtonClick() { shouldBeLandscape = landscape.isChecked(); try {/* w ww .j av a2 s . c o m*/ ProjectManager.getInstance().initializeNewProject(projectName, getActivity(), shouldBeEmpty, shouldBeLandscape); } catch (IllegalArgumentException illegalArgumentException) { Utils.showErrorDialog(getActivity(), R.string.error_project_exists); return; } catch (IOException ioException) { Utils.showErrorDialog(getActivity(), R.string.error_new_project); Log.e(TAG, Log.getStackTraceString(ioException)); dismiss(); return; } Intent intent = new Intent(getActivity(), ProjectActivity.class); intent.putExtra(Constants.PROJECTNAME_TO_LOAD, projectName); if (isOpenedFromProjectList()) { intent.putExtra(Constants.PROJECT_OPENED_FROM_PROJECTS_LIST, true); } getActivity().startActivity(intent); dismiss(); }
From source file:com.nbzs.ningbobus.ui.loaders.BusRunInfoReaderLoader.java
private BusLineRunInfoItem downloadOneFeedItem(Integer busLine) { try {//w w w . ja v a2s .co m URI newUri = URI.create(mFeedUri.toString() + "/" + Integer.toString(busLine) + "/?format=json"); HttpURLConnection conn = (HttpURLConnection) newUri.toURL().openConnection(); InputStream in; int status; conn.setDoInput(true); conn.setInstanceFollowRedirects(true); conn.setRequestProperty("User-Agent", getContext().getString(R.string.user_agent_string)); in = conn.getInputStream(); status = conn.getResponseCode(); if (status < 400) { String result = IOUtils.readStream(in); BusLineRunInfoItem item = new BusLineRunInfoItem(); //result = "{\"RunInfo\" : " + result + "}"; JSONObject jo = new JSONObject(result); //item.setBusLineName(jo.getString("Name")); item.setBusLineCurrentInfo(jo.getString("RunInfo")); //result = URLDecoder.decode(result, "UTF-8"); //item.setBusLineCurrentInfo(result); item.setBusLineName(FeedService.getBusLineFromId(getContext(), busLine)); return item; } conn.disconnect(); } catch (UnknownHostException e) { mActivity.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(mActivity, "No network connection.", Toast.LENGTH_SHORT).show(); } }); } catch (IOException e) { Log.d(TAG, "error reading feed"); Log.d(TAG, Log.getStackTraceString(e)); } catch (IllegalStateException e) { Log.d(TAG, "this should not happen"); Log.d(TAG, Log.getStackTraceString(e)); } catch (JSONException e) { Log.d(TAG, "this should not happen"); Log.d(TAG, Log.getStackTraceString(e)); } return null; }