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:org.maikelwever.droidpile.backend.ApiConnecter.java

public void setRemoteTotal(int total) {
    try {//w ww.  j av a 2s .c o  m
        List<DataCache> currentlyCached = new Select().from(DataCache.class)
                .where("key = ?", remoteTotalKeyName).execute();
        for (DataCache dc : currentlyCached) {
            dc.delete();
        }
    } catch (Exception e) {
        Log.d("droidpile", "No old cache entries to clear.");
        Log.d("droidpile", Log.getStackTraceString(e));
    }

    DataCache object = new DataCache();
    object.key = remoteTotalKeyName;
    object.data = Integer.toString(total);
    object.retrievedOn = new Date().getTime();
    object.save();
    Log.d("droidpile", "Stored total in cache. New total: " + Integer.toString(total));
}

From source file:android.support.v7.widget.BaseRecyclerViewInstrumentationTest.java

@After
public final void tearDown() throws Exception {
    if (mRecyclerView != null) {
        try {//from  w ww. j av  a 2 s . co  m
            removeRecyclerView();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
    }
    getInstrumentation().waitForIdleSync();

    try {
        checkForMainThreadException();
    } catch (Exception e) {
        throw e;
    } catch (Throwable throwable) {
        throw new Exception(Log.getStackTraceString(throwable));
    }
}

From source file:com.arantius.tivocommander.Utils.java

public final static void logError(String message, Throwable e) {
    Log.e(LOG_TAG, message, e);//  w  w  w  . j  a  v  a 2s .c  om
    logAddToBuffer(message, "E");
    logAddToBuffer(Log.getStackTraceString(e), "E");
}

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

@Nullable
private static String buildActivityList(Context context, File folder) {
    try {/*w  ww.j a va2 s. com*/
        File fileDir = new File(folder.toString() + "/" + "activity_list.xml");
        Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileDir), "UTF8"));

        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);

        List<ResolveInfo> appList = context.getPackageManager().queryIntentActivities(intent,
                PackageManager.GET_RESOLVED_FILTER);

        try {
            Collections.sort(appList, new ResolveInfo.DisplayNameComparator(context.getPackageManager()));
        } catch (Exception ignored) {
        }

        boolean first = true;
        for (ResolveInfo app : appList) {

            if (first) {
                first = false;
                out.append("<!-- ACTIVITY LIST -->");
                out.append("\n\n\n");
            }

            String name = app.activityInfo.loadLabel(context.getPackageManager()).toString();
            String activity = app.activityInfo.packageName + "/" + app.activityInfo.name;
            out.append("<!-- ").append(name).append(" -->");
            out.append("\n").append(activity);
            out.append("\n\n");
        }
        out.flush();
        out.close();

        return fileDir.toString();
    } catch (Exception | OutOfMemoryError e) {
        Log.d(Tag.LOG_TAG, Log.getStackTraceString(e));
    }
    return null;
}

From source file:org.centum.android.MainActivity.java

/**
 * Report uncaught exceptions (crashes) to Analytics
 *//*from  w ww  .  j  a  va2  s .c o m*/
private void setupUncaughtExceptionHandler() {
    ExceptionReporter myHandler = new ExceptionReporter(EasyTracker.getInstance(this),
            GAServiceManager.getInstance(), Thread.getDefaultUncaughtExceptionHandler(), this);

    StandardExceptionParser exceptionParser = new StandardExceptionParser(getApplicationContext(), null) {
        @Override
        public String getDescription(String threadName, Throwable t) {
            return "{" + threadName + "} " + "{" + Build.MODEL + "} " + "{" + Build.VERSION.SDK_INT + "} "
                    + Log.getStackTraceString(t);
        }
    };

    myHandler.setExceptionParser(exceptionParser);
    Thread.setDefaultUncaughtExceptionHandler(myHandler);
}

From source file:net.olejon.spotcommander.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Settings/*w  ww .  ja  va2s  .  com*/
    PreferenceManager.setDefaultValues(mContext, R.xml.settings, false);

    // Allow landscape?
    if (!mTools.allowLandscape())
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    // Google API client
    mGoogleApiClient = new GoogleApiClient.Builder(mContext).addApiIfAvailable(Wearable.API).build();

    // Database
    mDatabase = new MainSQLiteHelper(mContext).getWritableDatabase();

    // Layout
    setContentView(R.layout.activity_main);

    // Toolbar
    final Toolbar toolbar = (Toolbar) findViewById(R.id.main_toolbar);
    toolbar.setTitle(getString(R.string.main_title));

    setSupportActionBar(toolbar);

    // Listview
    mListView = (ListView) findViewById(R.id.main_list);

    final View listViewHeader = getLayoutInflater().inflate(R.layout.activity_main_subheader, mListView, false);
    mListView.addHeaderView(listViewHeader, null, false);

    final View listViewEmpty = findViewById(R.id.main_empty);
    mListView.setEmptyView(listViewEmpty);

    mListView.setLongClickable(true);

    mListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            openComputer(id);
        }
    });

    mListView.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, final long id) {
            new MaterialDialog.Builder(mContext).title(R.string.main_remove_computer_dialog_title)
                    .content(getString(R.string.main_remove_computer_dialog_message))
                    .positiveText(R.string.main_remove_computer_dialog_positive_button)
                    .negativeText(R.string.main_remove_computer_dialog_negative_button)
                    .onPositive(new MaterialDialog.SingleButtonCallback() {
                        @Override
                        public void onClick(@NonNull MaterialDialog materialDialog,
                                @NonNull DialogAction dialogAction) {
                            removeComputer(id);

                            listComputers();
                        }
                    }).contentColorRes(R.color.black).negativeColorRes(R.color.black).show();

            return true;
        }
    });

    // Floating action button
    mFloatingActionButton = (FloatingActionButton) findViewById(R.id.main_fab);

    mFloatingActionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(mContext, AddComputerActivity.class);
            startActivity(intent);
        }
    });

    // Donate button
    final Button button = (Button) findViewById(R.id.main_make_donation_button);

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(mContext, DonateActivity.class);
            startActivity(intent);
        }
    });

    // Information dialog
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        if (!mTools.getSharedPreferencesBoolean("HIDE_INFORMATION_DIALOG_75")) {
            new MaterialDialog.Builder(mContext).title(R.string.main_information_dialog_title)
                    .content(getString(R.string.main_information_dialog_message))
                    .positiveText(R.string.main_information_dialog_positive_button)
                    .onPositive(new MaterialDialog.SingleButtonCallback() {
                        @Override
                        public void onClick(@NonNull MaterialDialog materialDialog,
                                @NonNull DialogAction dialogAction) {
                            mTools.setSharedPreferencesBoolean("HIDE_INFORMATION_DIALOG_75", true);
                        }
                    }).contentColorRes(R.color.black).show();
        }
    }

    // Message dialog
    String version = mTools.getProjectVersionName();
    String device = "";

    try {
        device = (Build.MANUFACTURER == null || Build.MODEL == null || Build.VERSION.SDK_INT < 1) ? ""
                : URLEncoder.encode(Build.MANUFACTURER + " " + Build.MODEL + " " + Build.VERSION.SDK_INT,
                        "utf-8");
    } catch (Exception e) {
        Log.e("MainActivity", Log.getStackTraceString(e));
    }

    final Cache cache = new DiskBasedCache(getCacheDir(), 0);

    final Network network = new BasicNetwork(new HurlStack());

    final RequestQueue requestQueue = new RequestQueue(cache, network);

    requestQueue.start();

    final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,
            getString(R.string.project_website) + "api/1/android/message/?version_name=" + version + "&device="
                    + device,
            null, new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    requestQueue.stop();

                    try {
                        final long id = response.getLong("id");
                        final String title = response.getString("title");
                        final String message = response.getString("message");

                        final long lastId = mTools.getSharedPreferencesLong("LAST_MESSAGE_ID");

                        if (lastId == 0) {
                            mTools.setSharedPreferencesLong("LAST_MESSAGE_ID", id);
                        } else if (id != lastId) {
                            new MaterialDialog.Builder(mContext).title(title).content(message)
                                    .positiveText(R.string.main_message_dialog_positive_button)
                                    .onPositive(new MaterialDialog.SingleButtonCallback() {
                                        @Override
                                        public void onClick(@NonNull MaterialDialog materialDialog,
                                                @NonNull DialogAction dialogAction) {
                                            mTools.setSharedPreferencesLong("LAST_MESSAGE_ID", id);
                                        }
                                    }).contentColorRes(R.color.black).show();
                        }
                    } catch (Exception e) {
                        Log.e("MainActivity", Log.getStackTraceString(e));
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    requestQueue.stop();

                    Log.e("MainActivity", error.toString());
                }
            });

    jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

    requestQueue.add(jsonObjectRequest);

    // Google analytics
    final GoogleAnalytics googleAnalytics = GoogleAnalytics.getInstance(mContext);
    final Tracker tracker = googleAnalytics.newTracker(R.xml.app_tracker);
    tracker.send(new HitBuilders.ScreenViewBuilder().build());
}

From source file:org.cprados.wificellmanager.billing.Security.java

/** Invokes via reflection to the class EncodedPlublicKey. If class is available it returns 
 * the base64 encoded public key, otherwise defaults to ""
 *//*w w w. j ava  2 s .c o  m*/
private static String getBase64EncodedPublicKey() {
    String result = "";

    try {
        Class<?> encodedPublicKeyClass = Class.forName("org.cprados.wificellmanager.billing.EncodedPublicKey");
        Method method = encodedPublicKeyClass.getMethod("getBase64EncodedPublicKey");
        result = ((String) method.invoke(null));
    } catch (Exception e) {
        Log.e(TAG, Log.getStackTraceString(e));
    }
    return result;
}

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

/**
 * WARN  ?./*from  w  w  w .  ja v a2 s .c o m*/
 * 
 * @param clazz  ??  Class.
 * @param tr Throwable.
 */
public static void w(final Class<?> clazz, final Throwable tr) {
    if (LogUtil.isWarnEnabled()) {
        Log.println(Log.WARN, TAG, LogUtil.getClassLineNumber(clazz) + " - " + Log.getStackTraceString(tr));

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

From source file:eu.faircode.adblocker.Receiver.java

public static void notifyNewApplication(int uid, Context context) {
    if (uid < 0)
        return;/*  w w  w.  ja  v a 2 s .  c  o m*/

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    try {
        // Get application info
        String name = TextUtils.join(", ", Util.getApplicationNames(uid, context));

        // Get application info
        PackageManager pm = context.getPackageManager();
        String[] packages = pm.getPackagesForUid(uid);
        if (packages.length < 1)
            throw new PackageManager.NameNotFoundException(Integer.toString(uid));
        boolean internet = Util.hasInternet(uid, context);

        // Build notification
        Intent main = new Intent(context, ActivityMain.class);
        main.putExtra(ActivityMain.EXTRA_REFRESH, true);
        main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid));
        PendingIntent pi = PendingIntent.getActivity(context, uid, main, PendingIntent.FLAG_UPDATE_CURRENT);

        Util.setTheme(context);
        TypedValue tv = new TypedValue();
        context.getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_security_white_24dp)
                .setContentTitle(context.getString(R.string.app_name))
                .setContentText(context.getString(R.string.msg_installed, name)).setContentIntent(pi)
                .setColor(tv.data).setAutoCancel(true);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
        }

        // Get defaults
        SharedPreferences prefs_wifi = context.getSharedPreferences("wifi", Context.MODE_PRIVATE);
        SharedPreferences prefs_other = context.getSharedPreferences("other", Context.MODE_PRIVATE);
        boolean wifi = prefs_wifi.getBoolean(packages[0], prefs.getBoolean("whitelist_wifi", true));
        boolean other = prefs_other.getBoolean(packages[0], prefs.getBoolean("whitelist_other", true));

        // Build Wi-Fi action
        Intent riWifi = new Intent(context, ServiceSinkhole.class);
        riWifi.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set);
        riWifi.putExtra(ServiceSinkhole.EXTRA_NETWORK, "wifi");
        riWifi.putExtra(ServiceSinkhole.EXTRA_UID, uid);
        riWifi.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]);
        riWifi.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !wifi);

        PendingIntent piWifi = PendingIntent.getService(context, uid, riWifi,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(wifi ? R.drawable.wifi_on : R.drawable.wifi_off,
                context.getString(wifi ? R.string.title_allow : R.string.title_block), piWifi);

        // Build mobile action
        Intent riOther = new Intent(context, ServiceSinkhole.class);
        riOther.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set);
        riOther.putExtra(ServiceSinkhole.EXTRA_NETWORK, "other");
        riOther.putExtra(ServiceSinkhole.EXTRA_UID, uid);
        riOther.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]);
        riOther.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !other);
        PendingIntent piOther = PendingIntent.getService(context, uid + 10000, riOther,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(other ? R.drawable.other_on : R.drawable.other_off,
                context.getString(other ? R.string.title_allow : R.string.title_block), piOther);

        // Show notification
        if (internet)
            NotificationManagerCompat.from(context).notify(uid, builder.build());
        else {
            NotificationCompat.BigTextStyle expanded = new NotificationCompat.BigTextStyle(builder);
            expanded.bigText(context.getString(R.string.msg_installed, name));
            expanded.setSummaryText(context.getString(R.string.title_internet));
            NotificationManagerCompat.from(context).notify(uid, expanded.build());
        }

    } catch (PackageManager.NameNotFoundException ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }
}

From source file:org.alfresco.mobile.android.platform.exception.AlfrescoExceptionHelper.java

public static boolean checkEventException(FragmentActivity activity, OperationEvent event) {
    if (event.hasException) {
        int messageId = getMessageId(activity, event.exception);
        if (messageId != -1) {
            AlfrescoNotificationManager.getInstance(activity).showAlertCrouton(activity, messageId);
        }/*  w w w .  java 2  s .co  m*/
        Log.w("[ERROR]", Log.getStackTraceString(event.exception));
        return true;
    }
    return false;
}