List of usage examples for android.util Log getStackTraceString
public static String getStackTraceString(Throwable tr)
From source file:com.kth.common.utils.etc.LogUtil.java
/** * DEBUG ?./*from w w w. ja v a 2 s.co m*/ * * @param clazz ?? Class. * @param tr Throwable. */ public static void d(final Class<?> clazz, final Throwable tr) { if (LogUtil.isDebugEnabled()) { Log.println(Log.DEBUG, TAG, LogUtil.getClassLineNumber(clazz) + " - " + Log.getStackTraceString(tr)); // ?? ? ?. if (LogUtil.isFileLogEnabled()) { write(Log.DEBUG, LogUtil.getClassLineNumber(clazz), tr); } } }
From source file:com.dm.wallpaper.board.activities.WallpaperBoardSplashActivity.java
private void checkRszIo() { mCheckRszIo = new AsyncTask<Void, Void, Boolean>() { final String rszio = "https://rsz.io/"; @Override/*from ww w .java 2 s . co m*/ protected Boolean doInBackground(Void... voids) { while ((!isCancelled())) { try { Thread.sleep(1); URL url = new URL(rszio); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setReadTimeout(6000); connection.setConnectTimeout(6000); int code = connection.getResponseCode(); return code == 200; } catch (Exception e) { LogUtil.e(Log.getStackTraceString(e)); return false; } } return false; } @Override protected void onPostExecute(Boolean aBoolean) { super.onPostExecute(aBoolean); mCheckRszIo = null; WallpaperBoardActivity.sRszIoAvailable = aBoolean; LogUtil.e("rsz.io availability: " + WallpaperBoardActivity.sRszIoAvailable); } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:com.keylesspalace.tusky.util.NotificationHelper.java
/** * Takes a given Mastodon notification and either creates a new Android notification or updates * the state of the existing notification to reflect the new interaction. * * @param context to access application preferences and services * @param body a new Mastodon notification * @param account the account for which the notification should be shown *//*from ww w . jav a 2 s . c om*/ public static void make(final Context context, Notification body, AccountEntity account, boolean isFirstOfBatch) { if (!filterNotification(account, body, context)) { return; } String rawCurrentNotifications = account.getActiveNotifications(); JSONArray currentNotifications; BidiFormatter bidiFormatter = BidiFormatter.getInstance(); try { currentNotifications = new JSONArray(rawCurrentNotifications); } catch (JSONException e) { currentNotifications = new JSONArray(); } for (int i = 0; i < currentNotifications.length(); i++) { try { if (currentNotifications.getString(i).equals(body.getAccount().getName())) { currentNotifications.remove(i); break; } } catch (JSONException e) { Log.d(TAG, Log.getStackTraceString(e)); } } currentNotifications.put(body.getAccount().getName()); account.setActiveNotifications(currentNotifications.toString()); // Notification group member // ========================= final NotificationCompat.Builder builder = newNotification(context, body, account, false); notificationId++; builder.setContentTitle(titleForType(context, body, bidiFormatter)).setContentText(bodyForType(body)); if (body.getType() == Notification.Type.MENTION) { builder.setStyle(new NotificationCompat.BigTextStyle().bigText(bodyForType(body))); } //load the avatar synchronously Bitmap accountAvatar; try { accountAvatar = Picasso.with(context).load(body.getAccount().getAvatar()) .transform(new RoundedTransformation(20)).get(); } catch (IOException e) { Log.d(TAG, "error loading account avatar", e); accountAvatar = BitmapFactory.decodeResource(context.getResources(), R.drawable.avatar_default); } builder.setLargeIcon(accountAvatar); // Reply to mention action; RemoteInput is available from KitKat Watch, but buttons are available from Nougat if (body.getType() == Notification.Type.MENTION && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { RemoteInput replyRemoteInput = new RemoteInput.Builder(KEY_REPLY) .setLabel(context.getString(R.string.label_quick_reply)).build(); PendingIntent quickReplyPendingIntent = getStatusReplyIntent(REPLY_ACTION, context, body, account); NotificationCompat.Action quickReplyAction = new NotificationCompat.Action.Builder( R.drawable.ic_reply_24dp, context.getString(R.string.action_quick_reply), quickReplyPendingIntent).addRemoteInput(replyRemoteInput).build(); builder.addAction(quickReplyAction); PendingIntent composePendingIntent = getStatusReplyIntent(COMPOSE_ACTION, context, body, account); NotificationCompat.Action composeAction = new NotificationCompat.Action.Builder( R.drawable.ic_reply_24dp, context.getString(R.string.action_compose_shortcut), composePendingIntent).build(); builder.addAction(composeAction); } builder.setSubText(account.getFullName()); builder.setVisibility(NotificationCompat.VISIBILITY_PRIVATE); builder.setCategory(NotificationCompat.CATEGORY_SOCIAL); builder.setOnlyAlertOnce(true); // only alert for the first notification of a batch to avoid multiple alerts at once if (!isFirstOfBatch) { builder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY); } // Summary // ======= final NotificationCompat.Builder summaryBuilder = newNotification(context, body, account, true); if (currentNotifications.length() != 1) { try { String title = context.getString(R.string.notification_title_summary, currentNotifications.length()); String text = joinNames(context, currentNotifications, bidiFormatter); summaryBuilder.setContentTitle(title).setContentText(text); } catch (JSONException e) { Log.d(TAG, Log.getStackTraceString(e)); } } summaryBuilder.setSubText(account.getFullName()); summaryBuilder.setVisibility(NotificationCompat.VISIBILITY_PRIVATE); summaryBuilder.setCategory(NotificationCompat.CATEGORY_SOCIAL); summaryBuilder.setOnlyAlertOnce(true); summaryBuilder.setGroupSummary(true); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); //noinspection ConstantConditions notificationManager.notify(notificationId, builder.build()); if (currentNotifications.length() == 1) { notificationManager.notify((int) account.getId(), builder.setGroupSummary(true).build()); } else { notificationManager.notify((int) account.getId(), summaryBuilder.build()); } }
From source file:com.example.android.MainActivity.java
/**Display JSON data in table format on the user interface of android app * by clicking on the button 'Start'*/ @Override/*from w ww . j av a 2 s . com*/ protected void onCreate(Bundle savedInstanceState) { /** * Declares TextView, Button and Tablelayout to retrieve the widgets * from User Interface. Insert the TableRow into Table and set the * gravity, font size and id of table rows and columns. * * Due to great amount of JSON data, 'for' loop method is used to insert * the new rows and columns in the table. In each loop, each of rows and * columns are set to has its own unique id. This purpose of doing this * is to allows the user to read and write the text of specific rows and * columns easily. */ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); progress = new ProgressDialog(this); StartDisplay = (Button) findViewById(R.id.btnDisplay); profile = (TableLayout) findViewById(R.id.tableLayout1); profile.setStretchAllColumns(true); profile.bringToFront(); for (int i = 1; i < 11; i++) { TableRow tr = new TableRow(this); TextView c1 = new TextView(this); TextView c2 = new TextView(this); c1.setId(i * 10 + 1); c1.setTextSize(12); c1.setGravity(Gravity.CENTER); c2.setId(i * 10 + 2); c2.setTextSize(12); c2.setGravity(Gravity.CENTER); tr.addView(c1); tr.addView(c2); tr.setGravity(Gravity.CENTER_HORIZONTAL); profile.addView(tr); } /** * onClick: Executes the DownloadWebPageTask once OnClick event occurs. * When user click on the "Start" button, * 1)the JSON data will be read from URL * 2)Progress bar will be shown till all data is read and displayed in * table form. Once it reaches 100%, it will be dismissed. * * Progress Bar: The message of the progress bar is obtained from strings.xml. * New thread is created to handle the action of the progress bar. */ StartDisplay.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { final String TAG = "MyActivity"; progress.setMessage(getResources().getString(R.string.ProgressBar_message)); progress.setCancelable(true); progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progress.setProgress(0); progress.setMax(100); progress.show(); new Thread(new Runnable() { public void run() { while (ProgressBarStatus < 100) { try { Thread.sleep(500); } catch (InterruptedException e) { Log.e(TAG, Log.getStackTraceString(e)); } progressBarbHandler.post(new Runnable() { public void run() { progress.setProgress(ProgressBarStatus); } }); } if (ProgressBarStatus >= 100) { try { Thread.sleep(1000); } catch (InterruptedException e) { Log.e(TAG, Log.getStackTraceString(e)); } progress.dismiss(); } } }).start(); DownloadWebPageTask task = new DownloadWebPageTask(); task.execute("http://private-ae335-pgserverapi.apiary.io/user/profile/234"); StartDisplay.setClickable(false); } }); }
From source file:com.zhengde163.netguard.Receiver.java
@Override public void onReceive(final Context context, Intent intent) { Log.i(TAG, "Received " + intent); Util.logExtras(intent);/*w w w . j ava 2 s .c o m*/ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) { // Application added if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) { // Show notification if (prefs.getBoolean("install", true)) { int uid = intent.getIntExtra(Intent.EXTRA_UID, -1); notifyNewApplication(uid, context); } } } else if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) { // Application removed Rule.clearCache(context); if (intent.getBooleanExtra(Intent.EXTRA_DATA_REMOVED, false)) { // Remove settings String packageName = intent.getData().getSchemeSpecificPart(); Log.i(TAG, "Deleting settings package=" + packageName); context.getSharedPreferences("wifi", Context.MODE_PRIVATE).edit().remove(packageName).apply(); context.getSharedPreferences("other", Context.MODE_PRIVATE).edit().remove(packageName).apply(); context.getSharedPreferences("apply", Context.MODE_PRIVATE).edit().remove(packageName).apply(); context.getSharedPreferences("screen_wifi", Context.MODE_PRIVATE).edit().remove(packageName) .apply(); context.getSharedPreferences("screen_other", Context.MODE_PRIVATE).edit().remove(packageName) .apply(); context.getSharedPreferences("roaming", Context.MODE_PRIVATE).edit().remove(packageName).apply(); context.getSharedPreferences("notify", Context.MODE_PRIVATE).edit().remove(packageName).apply(); int uid = intent.getIntExtra(Intent.EXTRA_UID, 0); if (uid > 0) { DatabaseHelper.getInstance(context).clearAccess(uid, false); NotificationManagerCompat.from(context).cancel(uid); // installed notification NotificationManagerCompat.from(context).cancel(uid + 10000); // access notification } } } else { // Upgrade settings upgrade(true, context); // Start service try { if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { if (prefs.getBoolean("enabled", false) || prefs.getBoolean("show_stats", false)) ServiceSinkhole.start("receiver", context); } else if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) { if (prefs.getBoolean("enabled", false)) ServiceSinkhole.start("receiver", context); else if (prefs.getBoolean("show_stats", false)) ServiceSinkhole.run("receiver", context); } } catch (Throwable ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); Util.sendCrashReport(ex, context); } if (Util.isInteractive(context)) ServiceSinkhole.reloadStats("receiver", context); } }
From source file:eu.faircode.netguard.AdapterLog.java
public AdapterLog(Context context, Cursor cursor, boolean resolve, boolean organization) { super(context, cursor, 0); this.resolve = resolve; this.organization = organization; 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 w ww. ja v a 2 s . c om context.getTheme().resolveAttribute(R.attr.colorOff, tv, true); colorOff = tv.data; iconSize = Util.dips2pixels(24, context); try { List<InetAddress> lstDns = ServiceSinkhole.getDns(context); dns1 = (lstDns.size() > 0 ? lstDns.get(0) : null); dns2 = (lstDns.size() > 1 ? lstDns.get(1) : null); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); 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:com.master.metehan.filtereagle.Receiver.java
@Override public void onReceive(final Context context, Intent intent) { Log.i(TAG, "Received " + intent); Util.logExtras(intent);/*from w ww . j a va 2 s. com*/ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) { // Application added if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) { // Show notification if (IAB.isPurchased(ActivityPro.SKU_NOTIFY, context) && prefs.getBoolean("install", true)) { int uid = intent.getIntExtra(Intent.EXTRA_UID, -1); notifyNewApplication(uid, context); } } } else if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) { // Application removed Rule.clearCache(context); if (intent.getBooleanExtra(Intent.EXTRA_DATA_REMOVED, false)) { // Remove settings String packageName = intent.getData().getSchemeSpecificPart(); Log.i(TAG, "Deleting settings package=" + packageName); context.getSharedPreferences("wifi", Context.MODE_PRIVATE).edit().remove(packageName).apply(); context.getSharedPreferences("other", Context.MODE_PRIVATE).edit().remove(packageName).apply(); context.getSharedPreferences("apply", Context.MODE_PRIVATE).edit().remove(packageName).apply(); context.getSharedPreferences("screen_wifi", Context.MODE_PRIVATE).edit().remove(packageName) .apply(); context.getSharedPreferences("screen_other", Context.MODE_PRIVATE).edit().remove(packageName) .apply(); context.getSharedPreferences("roaming", Context.MODE_PRIVATE).edit().remove(packageName).apply(); context.getSharedPreferences("notify", Context.MODE_PRIVATE).edit().remove(packageName).apply(); int uid = intent.getIntExtra(Intent.EXTRA_UID, 0); if (uid > 0) { DatabaseHelper.getInstance(context).clearAccess(uid, false); NotificationManagerCompat.from(context).cancel(uid); // installed notification NotificationManagerCompat.from(context).cancel(uid + 10000); // access notification } } } else { // Upgrade settings upgrade(true, context); // Start service try { if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { if (prefs.getBoolean("enabled", false) || prefs.getBoolean("show_stats", false)) ServiceSinkhole.start("receiver", context); } else if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) { if (prefs.getBoolean("enabled", false)) ServiceSinkhole.start("receiver", context); else if (prefs.getBoolean("show_stats", false)) ServiceSinkhole.run("receiver", context); } } catch (Throwable ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); Util.sendCrashReport(ex, context); } if (Util.isInteractive(context)) ServiceSinkhole.reloadStats("receiver", context); } }
From source file:org.thoughtland.xlocation.Util.java
public static void bug(XHook hook, Throwable ex) { int priority; if (ex instanceof ActivityShare.AbortException) priority = Log.WARN;//from w ww .j av a 2s .com else if (ex instanceof ActivityShare.ServerException) priority = Log.WARN; else if (ex instanceof ConnectTimeoutException) priority = Log.WARN; else if (ex instanceof FileNotFoundException) priority = Log.WARN; else if (ex instanceof HttpHostConnectException) priority = Log.WARN; else if (ex instanceof NoClassDefFoundError) priority = Log.WARN; else if (ex instanceof OutOfMemoryError) priority = Log.WARN; else if (ex instanceof RuntimeException) priority = Log.WARN; else if (ex instanceof SecurityException) priority = Log.WARN; else if (ex instanceof SocketTimeoutException) priority = Log.WARN; else if (ex instanceof SSLPeerUnverifiedException) priority = Log.WARN; else if (ex instanceof TransactionTooLargeException) priority = Log.WARN; else if (ex instanceof UnknownHostException) priority = Log.WARN; else priority = Log.ERROR; boolean xlocation = false; for (StackTraceElement frame : ex.getStackTrace()) if (frame.getClassName() != null && frame.getClassName().startsWith("org.thoughtland.xlocation")) { xlocation = true; break; } if (!xlocation) priority = Log.WARN; log(hook, priority, ex.toString() + " uid=" + Process.myUid() + "\n" + Log.getStackTraceString(ex)); }
From source file:com.dm.wallpaper.board.fragments.FavoritesFragment.java
private void getWallpapers() { mGetWallpapers = new AsyncTask<Void, Void, Boolean>() { List<Wallpaper> wallpapers; @Override/* w ww. ja v a 2 s. c o m*/ protected void onPreExecute() { super.onPreExecute(); wallpapers = new ArrayList<>(); } @Override protected Boolean doInBackground(Void... voids) { while (!isCancelled()) { try { Thread.sleep(1); wallpapers = Database.get(getActivity()).getFavoriteWallpapers(); 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) { mRecyclerView.setAdapter(new WallpapersAdapter(getActivity(), wallpapers, true, false)); if (mRecyclerView.getAdapter().getItemCount() == 0) { int color = ColorHelper.getAttributeColor(getActivity(), android.R.attr.textColorSecondary); mFavoriteEmpty.setImageDrawable(DrawableHelper.getTintedDrawable(getActivity(), R.drawable.ic_wallpaper_favorite_empty, ColorHelper.setColorAlpha(color, 0.7f))); mFavoriteEmpty.setVisibility(View.VISIBLE); } } mGetWallpapers = null; } }.execute(); }
From source file:com.amazon.cordova.plugin.ADMMessageHandler.java
/** {@inheritDoc} */ @Override// w w w. j a v a 2 s .c om protected void onRegistrationError(final String errorId) { // You should consider a registration error fatal. In response, your app // may degrade gracefully, or you may wish to notify the user that this part // of your app's functionality is not available. try { JSONObject json; json = new JSONObject().put(PushPlugin.EVENT, ERROR_EVENT); json.put(ADMMessageHandler.ERROR_MSG, errorId); PushPlugin.sendJavascript(json); } catch (Exception e) { Log.getStackTraceString(e); } }