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.kth.common.utils.etc.LogUtil.java

/**
 * VERBOSE  ?./*  ww w. ja  v  a2  s .  c o  m*/
 * 
 * @param clazz  ??  Class.
 * @param msg .
 * @param tr Throwable.
 */
public static void v(final Class<?> clazz, final String msg, final Throwable tr) {
    if (LogUtil.isVerboseEnabled()) {
        Log.println(Log.VERBOSE, TAG,
                LogUtil.getClassLineNumber(clazz) + " - " + msg + '\n' + Log.getStackTraceString(tr));

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

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

public void setPreferenceForceDebug(boolean forceDebug) {
    if (this.preferences == null) {
        Log.e(LOG_TAG, "getSharedPreferences() returned null. Setting force debug is disabled.");
    } else if (forceDebug != this.forceDebug) {
        try {//from w ww . jav  a 2s  .  c om
            SharedPreferences.Editor editor = this.preferences.edit();
            editor.putBoolean(PREFERENCE_FORCE_DEBUG, forceDebug);
            editor.apply();
            Log.d(LOG_TAG, String.format(Locale.US, "Force debug is now %s, please re-start the app.",
                    forceDebug ? "enabled" : "disabled"));
        } catch (Exception e) {
            Log.e(LOG_TAG, "Error occurred while storing preferences. " + Log.getStackTraceString(e));
        }
    }
}

From source file:org.erlymon.litvak.core.presenter.SignInPresenterImpl.java

@Override
public void onSignInButtonClick() {

    if (!subscription.isUnsubscribed()) {
        subscription.unsubscribe();/*from  ww w. j a v  a  2s . c  o  m*/
    }

    view.showProgressDialog();
    subscription = model.createSession(view.getLogin(), view.getPassword()).subscribeOn(Schedulers.io())
            //.flatMap(user -> model.getDevices().flatMap(devices -> Observable.just(new Pair<>(user, devices))))
            .flatMap(
                    user -> Observable
                            .zip(model.getDevices(), model.getLatestPositions(),
                                    (devices, positions) -> new Triple<>(user, devices, positions))
                            .asObservable())
            .observeOn(AndroidSchedulers.mainThread()).doOnNext(result -> realmdb.executeTransaction(realm -> {
                realm.copyToRealmOrUpdate(result.first);
                realm.copyToRealmOrUpdate(Arrays.asList(result.second));
                realm.copyToRealmOrUpdate(Arrays.asList(result.third));
            })).subscribe(new Observer<Triple<User, Device[], Position[]>>() {
                @Override
                public void onCompleted() {

                }

                @Override
                public void onError(Throwable e) {
                    logger.error(Log.getStackTraceString(e));
                    view.showError(e.getMessage());
                    view.hideProgressDialog();
                }

                @Override
                public void onNext(Triple<User, Device[], Position[]> result) {
                    view.showData(result.first);
                    view.hideProgressDialog();
                }
            });
}

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

@Nullable
public static String saveIcon(File directory, Bitmap bitmap, String name) {
    String fileName = name.toLowerCase().replace(" ", "_") + ".png";
    File file = new File(directory, fileName);
    try {//  w  w w . j  a va  2  s .com
        FileOutputStream outStream = new FileOutputStream(file);
        bitmap.compress(Bitmap.CompressFormat.PNG, 50, outStream);
        outStream.flush();
        outStream.close();
        return directory.toString() + "/" + fileName;
    } catch (Exception | OutOfMemoryError e) {
        LogUtil.e(Log.getStackTraceString(e));
    }
    return null;
}

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

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 1) {
        final String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");

        if (resultCode == RESULT_OK) {
            try {
                final JSONObject purchaseDataJsonObject = new JSONObject(purchaseData);
                final String purchaseToken = purchaseDataJsonObject.getString("purchaseToken");

                consumeDonation(purchaseToken);

                mTools.showToast(getString(R.string.donate_thank_you), 1);

                finish();//from   www.  j av  a  2 s  .  c o m
            } catch (Exception e) {
                mTools.showToast(getString(R.string.donate_something_went_wrong), 1);

                Log.e("DonateActivity", Log.getStackTraceString(e));
            }
        }
    }
}

From source file:io.v.syncslides.DeckChooserActivity.java

private void handleError(String msg, Throwable throwable) {
    Log.e(TAG, msg + ": " + Log.getStackTraceString(throwable));
    Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show();
}

From source file:com.twolinessoftware.smarterlist.view.MasterSmartListItemSearchAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {

    GenericListViewHolder holder = (GenericListViewHolder) view.getTag();

    try {/* w ww  .  ja  va  2s. c  o  m*/
        final MasterSmartListItem item = m_masterListItemDao.fromCursor(cursor);

        boolean isIncludedInSmartList = m_smartListService.containsItem(item.getId(), m_smartListId);

        holder.getView().setOnClickListener(v1 -> {
            m_eventBus.post(new OnListItemSelectedEvent(item));
        });

        holder.setText(item.getName());
        holder.textMain.setTextColor(item.getCategoryColor());
        holder.colorSideBar.setBackgroundColor(item.getCategoryColor());

        if (isIncludedInSmartList) {
            holder.icon.setImageResource(R.drawable.ic_check);
        } else {
            TextDrawable textDrawable = new TextDrawable(m_context, item.getName().substring(0, 1));
            holder.icon.setImageDrawable(textDrawable);
        }

        holder.icon.setVisibility(View.VISIBLE);
    } catch (Exception e) {
        Ln.e("Unable to parse cursor:" + Log.getStackTraceString(e));
    }

}

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

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

    try {/*from  ww w  . j  a va 2 s  . co m*/
        request(Constants.FRIENDSHIPS_GROUPS_DESTROY, params, HTTP_POST);
    } catch (Exception e) {
        if (DEBUG) {
            Log.e(TAG, "Cannot destroy group");
            Log.e(TAG, Log.getStackTraceString(e));
        }
    }
}

From source file:com.kogitune.launcher3.LauncherAppWidgetHostView.java

@Override
public void updateAppWidget(RemoteViews remoteViews) {
    if (EXPERIMENTAL) {
        if (remoteViews != null) {
            Handler mH = null;/*from   ww  w  . j av  a  2  s.c  om*/
            Field queueField = null;
            MessageQueue messageQueue = null;
            try {
                Class<?> activityThreadClass = Class.forName("android.app.ActivityThread");
                Class[] params = new Class[0];
                Method currentActivityThread = activityThreadClass.getDeclaredMethod("currentActivityThread",
                        params);
                Boolean accessible = currentActivityThread.isAccessible();
                currentActivityThread.setAccessible(true);
                Object obj = currentActivityThread.invoke(activityThreadClass);
                if (obj == null) {
                    Log.d("ERROR", "The current activity thread is null!");
                }
                currentActivityThread.setAccessible(accessible);

                Field mHField = activityThreadClass.getDeclaredField("mH");
                mHField.setAccessible(true);
                mH = (Handler) mHField.get(obj);
                queueField = Handler.class.getDeclaredField("mQueue");
                queueField.setAccessible(true);
                messageQueue = (MessageQueue) queueField.get(mH);

                HandlerThread handlerThread = new HandlerThread("other");
                handlerThread.start();
                handlerThread.quit();
                queueField.set(mH, null);

            } catch (Exception e) {
                Log.d("ERROR", Log.getStackTraceString(e));
            }
            Context context = getContext().getApplicationContext();
            NotificationManager notificationManager = (NotificationManager) context.getApplicationContext()
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
            builder.setContent(remoteViews).setSmallIcon(R.drawable.ic_launcher_info_normal_holo)
                    .setContentTitle("My notification") // ?
                    .setContentText("Hello Notification!!"); // ?

            Notification notification = builder.build();
            notificationManager.notify(getAppWidgetId(), notification);

            final Field finalQueueField = queueField;
            final Handler finalMH = mH;
            final MessageQueue finalMessageQueue = messageQueue;
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        Thread.sleep(50L);
                        if (finalMessageQueue != null)
                            finalQueueField.set(finalMH, finalMessageQueue);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).start();

        }
    }
    // Store the orientation in which the widget was inflated
    mPreviousOrientation = mContext.getResources().getConfiguration().orientation;
    super.updateAppWidget(remoteViews);
}

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

public JSONObject querySkuDetails(String sku) {
    try {//from  w w w  . j  ava  2s  . c  o m
        Class<?> purchasingServiceClass = Class.forName("com.amazon.device.iap.PurchasingService");
        Method m = purchasingServiceClass.getMethod("getProductData", Set.class);
        HashSet<String> skus = new HashSet<>();
        skus.add(sku);
        Object requestId = m.invoke(null, skus);

        skuDetailsRequestMap.put(requestId.toString(), requestId);
        synchronized (requestId) {
            requestId.wait();
        }
        skuDetailsRequestMap.remove(requestId.toString());

        JSONObject ret = new JSONObject();
        ret.put("price_string", skuPriceMap.get(sku));
        return ret;
    } catch (Exception e) {
        Log.e(LOG_TAG, "Reflection error: " + Log.getStackTraceString(e));
        Teak.sdkRaven.reportException(e);
    }
    return null;
}