Example usage for android.util Log getStackTraceString

List of usage examples for android.util Log getStackTraceString

Introduction

In this page you can find the example usage for android.util Log getStackTraceString.

Prototype

public static String getStackTraceString(Throwable tr) 

Source Link

Document

Handy function to get a loggable stack trace from a Throwable

Usage

From source file:com.dm.material.dashboard.candybar.helpers.DrawableHelper.java

@Nullable
public static Drawable getResizedDrawable(@NonNull Context context, @DrawableRes int drawableRes,
        @DimenRes int dimenRes) {
    try {/*from w  ww.j  a  v  a2s.  c  o m*/
        Drawable drawable = getDrawable(context, drawableRes);
        if (drawable == null)
            return null;

        int size = context.getResources().getDimensionPixelSize(dimenRes);

        Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);

        return new BitmapDrawable(context.getResources(), Bitmap.createScaledBitmap(bitmap, size, size, true));
    } catch (Exception | OutOfMemoryError e) {
        LogUtil.d(Log.getStackTraceString(e));
        return null;
    }
}

From source file:com.kth.common.utils.etc.LogUtil.java

/**
 * VERBOSE  ?./*from   w  ww .j ava2 s  .co m*/
 * 
 * @param clazz  ??  Class.
 * @param tr Throwable.
 */
public static void v(final Class<?> clazz, final Throwable tr) {
    if (LogUtil.isVerboseEnabled()) {
        Log.println(Log.VERBOSE, TAG, LogUtil.getClassLineNumber(clazz) + " - " + Log.getStackTraceString(tr));

        //  ?? ?   ?.
        if (LogUtil.isFileLogEnabled()) {
            write(Log.VERBOSE, LogUtil.getClassLineNumber(clazz), tr);
        }
    }
}

From source file:io.teak.sdk.Amazon.java

public void onActivityResumed() {
    // Get user data and insert it into the dynamic common payload
    try {/*from   ww  w . j  av  a2  s .co  m*/
        Class<?> purchasingServiceClass = Class.forName("com.amazon.device.iap.PurchasingService");
        Method m = purchasingServiceClass.getMethod("getUserData");
        m.invoke(null);
    } catch (Exception e) {
        Log.e(LOG_TAG, "Reflection error: " + Log.getStackTraceString(e));
        Teak.sdkRaven.reportException(e);
    }
}

From source file:org.alfresco.mobile.android.application.capture.AudioCapture.java

@Override
public boolean captureData() {
    if (hasDevice()) {
        try {/*  ww  w  . j a  v a 2 s  .c  o  m*/
            Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
            if (intent.resolveActivity(context.getPackageManager()) == null) {
                AlfrescoNotificationManager.getInstance(context).showAlertCrouton(parentActivity,
                        context.getString(R.string.feature_disable));
                return false;
            } else {
                parentActivity.startActivityForResult(intent, getRequestCode());
            }
        } catch (Exception e) {
            AlfrescoNotificationManager.getInstance(context).showAlertCrouton(parentActivity,
                    context.getString(R.string.no_voice_recorder));
            Log.d(TAG, Log.getStackTraceString(e));
            return false;
        }

        return true;
    } else {
        return false;
    }
}

From source file:info.papdt.blacklight.api.friendships.GroupsApi.java

public static void removeMemberFromGroup(String uid, String groupId) {
    WeiboParameters params = new WeiboParameters();
    params.put("uid", uid);
    params.put("list_id", groupId);

    try {/*w  w  w.  j  a  v a 2  s.  c o  m*/
        request(Constants.FRIENDSHIPS_GROUPS_MEMBERS_DESTROY, params, HTTP_POST);
    } catch (Exception e) {
        if (DEBUG) {
            Log.e(TAG, "Cannot remove user from group");
            Log.e(TAG, Log.getStackTraceString(e));
        }
    }
}

From source file:org.proninyaroslav.libretorrent.core.IPFilterParser.java

public static boolean parseDATFilterFile(String path, ip_filter filter) {
    if (path == null || filter == null) {
        return false;
    }/* w w  w.ja  va2  s  .  c o  m*/

    File file = new File(path);
    if (!file.exists()) {
        return false;
    }

    LineIterator it = null;

    try {
        it = FileUtils.lineIterator(file, "UTF-8");

    } catch (IOException e) {
        Log.e(TAG, Log.getStackTraceString(e));
    }

    if (it == null) {
        return false;
    }

    long lineNum = 0;
    long badLineNum = 0;
    try {
        while (it.hasNext()) {
            ++lineNum;
            String line = it.nextLine();

            line = line.trim();
            if (line.isEmpty()) {
                continue;
            }

            /* Ignoring commented lines */
            if (line.startsWith("#") || line.startsWith("//")) {
                continue;
            }

            /* Line should be split by commas */
            String[] parts = line.split(",");
            long elementNum = parts.length;

            /* IP Range should be split by a dash */
            String[] ips = parts[0].split("-");
            if (ips.length != 2) {
                Log.w(TAG, "parseDATFilterFile: line " + lineNum + " is malformed.");
                Log.w(TAG, "Line was " + line);
                ++badLineNum;
                continue;
            }

            String startIp = cleanupIPAddress(ips[0]);
            if (startIp == null || startIp.isEmpty()) {
                Log.w(TAG, "parseDATFilterFile: line " + lineNum + " is malformed.");
                Log.w(TAG, "Start IP of the range is malformated: " + ips[0]);
                ++badLineNum;
                continue;
            }

            error_code error = new error_code();
            address startAddr = address.from_string(startIp, error);
            if (error.value() > 0) {
                Log.w(TAG, "parseDATFilterFile: line " + lineNum + " is malformed.");
                Log.w(TAG, "Start IP of the range is malformated:" + ips[0]);
                ++badLineNum;
                continue;
            }

            String endIp = cleanupIPAddress(ips[1]);
            if (endIp == null || endIp.isEmpty()) {
                Log.w(TAG, "parseDATFilterFile: line " + lineNum + " is malformed.");
                Log.w(TAG, "End IP of the range is malformated: " + ips[1]);
                ++badLineNum;
                continue;
            }

            address endAddr = address.from_string(endIp, error);
            if (error.value() > 0) {
                Log.w(TAG, "parseDATFilterFile: line " + lineNum + " is malformed.");
                Log.w(TAG, "End IP of the range is malformated:" + ips[1]);
                ++badLineNum;
                continue;
            }

            if (startAddr.is_v4() != endAddr.is_v4()) {
                Log.w(TAG, "parseDATFilterFile: line " + lineNum + " is malformed.");
                Log.w(TAG, "One IP is IPv4 and the other is IPv6!");
                ++badLineNum;
                continue;
            }

            /* Check if there is an access value (apparently not mandatory) */
            int accessNum = 0;
            if (elementNum > 1) {
                /* There is possibly one */
                accessNum = Integer.parseInt(parts[1].trim());
            }

            /* Ignoring this rule because access value is too high */
            if (accessNum > 127) {
                continue;
            }

            try {
                filter.add_rule(startAddr, endAddr, ip_filter.access_flags.blocked.swigValue());

            } catch (Exception e) {
                Log.w(TAG, "parseDATFilterFile: line " + lineNum + " is malformed.");
                Log.w(TAG, "Line was " + line);
                ++badLineNum;
            }
        }

    } finally {
        it.close();
    }

    return badLineNum < lineNum;
}

From source file:com.dm.material.dashboard.candybar.helpers.ReportBugsHelper.java

public static void checkForBugs(@NonNull Context context) {
    new AsyncTask<Void, Void, Boolean>() {

        MaterialDialog dialog;/* w  ww .  j a v a2 s  .co  m*/
        StringBuilder sb;
        File folder;
        String file;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            sb = new StringBuilder();
            folder = FileHelper.getCacheDirectory(context);
            file = folder.toString() + "/" + "reportbugs.zip";

            MaterialDialog.Builder builder = new MaterialDialog.Builder(context);
            builder.content(R.string.report_bugs_building).progress(true, 0).progressIndeterminateStyle(true);

            dialog = builder.build();
            dialog.show();
        }

        @Override
        protected Boolean doInBackground(Void... voids) {
            while (!isCancelled()) {
                try {
                    Thread.sleep(1);
                    SparseArrayCompat<String> files = new SparseArrayCompat<>();
                    sb.append(DeviceHelper.getDeviceInfo(context));

                    String brokenAppFilter = buildBrokenAppFilter(context, folder);
                    if (brokenAppFilter != null)
                        files.append(files.size(), brokenAppFilter);

                    String activityList = buildActivityList(context, folder);
                    if (activityList != null)
                        files.append(files.size(), activityList);

                    String stackTrace = Preferences.getPreferences(context).getLatestCrashLog();
                    String crashLog = buildCrashLog(context, folder, stackTrace);
                    if (crashLog != null)
                        files.append(files.size(), crashLog);

                    FileHelper.createZip(files, file);
                    return true;
                } catch (Exception e) {
                    Log.d(Tag.LOG_TAG, Log.getStackTraceString(e));
                    return false;
                }
            }
            return false;
        }

        @Override
        protected void onPostExecute(Boolean aBoolean) {
            super.onPostExecute(aBoolean);
            dialog.dismiss();
            if (aBoolean) {
                File zip = new File(file);

                final Intent intent = new Intent(Intent.ACTION_SEND);
                intent.setType("message/rfc822");
                intent.putExtra(Intent.EXTRA_EMAIL,
                        new String[] { context.getResources().getString(R.string.dev_email) });
                intent.putExtra(Intent.EXTRA_SUBJECT, "Report Bugs " + (context.getString(R.string.app_name)));
                intent.putExtra(Intent.EXTRA_TEXT, sb.toString());
                Uri uri = FileHelper.getUriFromFile(context, context.getPackageName(), zip);
                intent.putExtra(Intent.EXTRA_STREAM, uri);

                context.startActivity(
                        Intent.createChooser(intent, context.getResources().getString(R.string.email_client)));

            } else {
                Toast.makeText(context, R.string.report_bugs_failed, Toast.LENGTH_LONG).show();
            }

            dialog = null;
            sb.setLength(0);
        }
    }.execute();
}

From source file:com.keylesspalace.tusky.util.NotificationManager.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 notifyId an arbitrary number to reference this notification for any future action
 * @param body     a new Mastodon notification
 *///from  w w w  .  j  a v  a  2  s . co  m
public static void make(final Context context, final int notifyId, Notification body) {
    final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    final SharedPreferences notificationPreferences = context.getSharedPreferences("Notifications",
            Context.MODE_PRIVATE);

    if (!filterNotification(preferences, body)) {
        return;
    }

    createNotificationChannels(context);

    String rawCurrentNotifications = notificationPreferences.getString("current", "[]");
    JSONArray currentNotifications;

    try {
        currentNotifications = new JSONArray(rawCurrentNotifications);
    } catch (JSONException e) {
        currentNotifications = new JSONArray();
    }

    boolean alreadyContains = false;

    for (int i = 0; i < currentNotifications.length(); i++) {
        try {
            if (currentNotifications.getString(i).equals(body.account.getDisplayName())) {
                alreadyContains = true;
            }
        } catch (JSONException e) {
            Log.d(TAG, Log.getStackTraceString(e));
        }
    }

    if (!alreadyContains) {
        currentNotifications.put(body.account.getDisplayName());
    }

    notificationPreferences.edit().putString("current", currentNotifications.toString()).apply();

    Intent resultIntent = new Intent(context, MainActivity.class);
    resultIntent.putExtra("tab_position", 1);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    Intent deleteIntent = new Intent(context, NotificationClearBroadcastReceiver.class);
    PendingIntent deletePendingIntent = PendingIntent.getBroadcast(context, 0, deleteIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context, getChannelId(body))
            .setSmallIcon(R.drawable.ic_notify).setContentIntent(resultPendingIntent)
            .setDeleteIntent(deletePendingIntent).setColor(ContextCompat.getColor(context, (R.color.primary)))
            .setDefaults(0); // So it doesn't ring twice, notify only in Target callback

    setupPreferences(preferences, builder);

    if (currentNotifications.length() == 1) {
        builder.setContentTitle(titleForType(context, body))
                .setContentText(truncateWithEllipses(bodyForType(body), 40));

        //load the avatar synchronously
        Bitmap accountAvatar;
        try {
            accountAvatar = Picasso.with(context).load(body.account.avatar)
                    .transform(new RoundedTransformation(7, 0)).get();
        } catch (IOException e) {
            Log.d(TAG, "error loading account avatar", e);
            accountAvatar = BitmapFactory.decodeResource(context.getResources(), R.drawable.avatar_default);
        }

        builder.setLargeIcon(accountAvatar);

    } else {
        try {
            String format = context.getString(R.string.notification_title_summary);
            String title = String.format(format, currentNotifications.length());
            String text = truncateWithEllipses(joinNames(context, currentNotifications), 40);
            builder.setContentTitle(title).setContentText(text);
        } catch (JSONException e) {
            Log.d(TAG, Log.getStackTraceString(e));
        }
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setVisibility(android.app.Notification.VISIBILITY_PRIVATE);
        builder.setCategory(android.app.Notification.CATEGORY_SOCIAL);
    }

    android.app.NotificationManager notificationManager = (android.app.NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    //noinspection ConstantConditions
    notificationManager.notify(notifyId, builder.build());
}

From source file:org.catrobat.catroid.transfers.CheckTokenTask.java

@Override
protected Boolean doInBackground(Void... arg0) {
    try {// ww w  . j a  v  a2  s  .c  o  m
        if (!Utils.isNetworkAvailable(fragmentActivity)) {
            exception = new WebconnectionException(WebconnectionException.ERROR_NETWORK,
                    "Network not available!");
            return false;
        }

        return ServerCalls.getInstance().checkToken(token, username);
    } catch (WebconnectionException webconnectionException) {
        Log.e(TAG, Log.getStackTraceString(webconnectionException));
        exception = webconnectionException;
    }
    return false;
}

From source file:com.dm.material.dashboard.candybar.helpers.FileHelper.java

public static void createZip(@NonNull List<String> files, String directory) {
    try {//w w w.  ja  v  a2  s .co m
        BufferedInputStream origin;
        FileOutputStream dest = new FileOutputStream(directory);
        ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest));
        byte data[] = new byte[BUFFER];
        for (int i = 0; i < files.size(); i++) {
            FileInputStream fi = new FileInputStream(files.get(i));
            origin = new BufferedInputStream(fi, BUFFER);

            ZipEntry entry = new ZipEntry(files.get(i).substring(files.get(i).lastIndexOf("/") + 1));
            out.putNextEntry(entry);
            int count;

            while ((count = origin.read(data, 0, BUFFER)) != -1) {
                out.write(data, 0, count);
            }
            origin.close();
        }

        out.close();
    } catch (Exception e) {
        LogUtil.e(Log.getStackTraceString(e));
    }
}