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.huison.DriverAssistant_Web.util.LoginHelper.java

public static void forgetPassword(final BaseActivity activity, final String username) {
    UmengEventSender.sendEvent(activity, UmengEventTypes.forgetPW);
    final ProgressDialog pd = new ProgressDialog(activity);
    pd.setMessage("");
    pd.show();/*  w  ww  .  j a v  a  2 s. c  o m*/
    AsyncHttpClient client = activity.getAsyncHttpClient();
    RequestParams params = new RequestParams();
    /*
     * Map<String, String> map = new HashMap<String, String>();
     * map.put("sessionkey", BaseActivity.getSESSIONKEY());
     * map.put("userid", username); map.put("mob", phone);
     * map.put("version", activity.getVersionName()); params.put("action",
     * FORGET_PASSWORD_ACTION); params.put("xml", BaseActivity.getXML(map));
     * Log.v("XML:",BaseActivity.getXML(map));
     */
    try {
        JSONObject p = new JSONObject();
        p.put("mobile", username);
        p.put("password", "wangjile");
        p.put("method", "forget");
        p.put("version", activity.getVersionName());
        p.put("devicetype", "android");
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date curDate = new Date(System.currentTimeMillis());// 
        String time = formatter.format(curDate);
        p.put("time", time);
        Log.v("", p.toString());
        String data = Util.DesJiaMi(p.toString(), "czxms520");
        // Log.v("",data);
        params.put("data", data);
    } catch (Exception e) {
        e.printStackTrace();
    }
    client.post(BaseActivity.REQUESTURL, params, new JsonHttpResponseHandler() {
        @Override
        public void onDispatchSuccess(int statusCode, Header[] headers, String result) {
            pd.dismiss();
            try {
                result = Util.decrypt(result, "czxms520");
                Log.v(TAG, "JSON" + result);
                JSONObject jo = new JSONObject(result);
                String code = jo.getString("code");
                String msg = getJSONValueAsString(jo, "message");
                if (code.equals("0")) {
                    activity.showMessageBoxAndFinish(msg);
                } else {
                    activity.showMessageBox(msg);
                }
            } catch (JSONException e) {
                activity.showMessageBox(activity.getText(R.string.server404));
                Log.e("change password error", Log.getStackTraceString(e));
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        @Override
        public void onFailureAnyway(int statusCode, Header[] headers, Throwable throwable,
                BaseBinaryResponse jsonResponse) {
            pd.dismiss();
            activity.showMessageBox(activity.getText(R.string.server404));
        }

        @Override
        public void onSuccessAnyway(int statusCode, Header[] headers, BaseBinaryResponse jsonResponse) {
        }
    });
    TimeCounter.countTime(activity, pd);
}

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

public static void sendCrashReport(Throwable ex, final Context context) {
    if (!isPlayStoreInstall(context))
        return;/*from   ww  w .j  a  va 2s  . c  o m*/

    try {
        ApplicationErrorReport report = new ApplicationErrorReport();
        report.packageName = report.processName = context.getPackageName();
        report.time = System.currentTimeMillis();
        report.type = ApplicationErrorReport.TYPE_CRASH;
        report.systemApp = false;

        ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo();
        crash.exceptionClassName = ex.getClass().getSimpleName();
        crash.exceptionMessage = ex.getMessage();

        StringWriter writer = new StringWriter();
        PrintWriter printer = new PrintWriter(writer);
        ex.printStackTrace(printer);

        crash.stackTrace = writer.toString();

        StackTraceElement stack = ex.getStackTrace()[0];
        crash.throwClassName = stack.getClassName();
        crash.throwFileName = stack.getFileName();
        crash.throwLineNumber = stack.getLineNumber();
        crash.throwMethodName = stack.getMethodName();

        report.crashInfo = crash;

        final Intent bug = new Intent(Intent.ACTION_APP_ERROR);
        bug.putExtra(Intent.EXTRA_BUG_REPORT, report);
        bug.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (bug.resolveActivity(context.getPackageManager()) != null)
            context.startActivity(bug);
    } catch (Throwable exex) {
        Log.e(TAG, exex.toString() + "\n" + Log.getStackTraceString(exex));
    }
}

From source file:android_network.hetnet.vpn_service.Util.java

public static void sendCrashReport(Throwable ex, final Context context) {
    if (!isPlayStoreInstall(context) || Util.isDebuggable(context))
        return;//  w w w.ja  v  a 2 s.  co m

    try {
        ApplicationErrorReport report = new ApplicationErrorReport();
        report.packageName = report.processName = context.getPackageName();
        report.time = System.currentTimeMillis();
        report.type = ApplicationErrorReport.TYPE_CRASH;
        report.systemApp = false;

        ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo();
        crash.exceptionClassName = ex.getClass().getSimpleName();
        crash.exceptionMessage = ex.getMessage();

        StringWriter writer = new StringWriter();
        PrintWriter printer = new PrintWriter(writer);
        ex.printStackTrace(printer);

        crash.stackTrace = writer.toString();

        StackTraceElement stack = ex.getStackTrace()[0];
        crash.throwClassName = stack.getClassName();
        crash.throwFileName = stack.getFileName();
        crash.throwLineNumber = stack.getLineNumber();
        crash.throwMethodName = stack.getMethodName();

        report.crashInfo = crash;

        final Intent bug = new Intent(Intent.ACTION_APP_ERROR);
        bug.putExtra(Intent.EXTRA_BUG_REPORT, report);
        bug.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (bug.resolveActivity(context.getPackageManager()) != null)
            context.startActivity(bug);
    } catch (Throwable exex) {
        Log.e(TAG, exex.toString() + "\n" + Log.getStackTraceString(exex));
    }
}

From source file:com.master.metehan.filtereagle.Util.java

public static void sendCrashReport(Throwable ex, final Context context) {
    if (!isPlayStoreInstall(context))
        return;/* w w w.ja v  a2s  .  co  m*/
    if (!(Util.isDebuggable(context) || Util.getSelfVersionName(context).contains("beta")))
        return;

    try {
        ApplicationErrorReport report = new ApplicationErrorReport();
        report.packageName = report.processName = context.getPackageName();
        report.time = System.currentTimeMillis();
        report.type = ApplicationErrorReport.TYPE_CRASH;
        report.systemApp = false;

        ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo();
        crash.exceptionClassName = ex.getClass().getSimpleName();
        crash.exceptionMessage = ex.getMessage();

        StringWriter writer = new StringWriter();
        PrintWriter printer = new PrintWriter(writer);
        ex.printStackTrace(printer);

        crash.stackTrace = writer.toString();

        StackTraceElement stack = ex.getStackTrace()[0];
        crash.throwClassName = stack.getClassName();
        crash.throwFileName = stack.getFileName();
        crash.throwLineNumber = stack.getLineNumber();
        crash.throwMethodName = stack.getMethodName();

        report.crashInfo = crash;

        final Intent bug = new Intent(Intent.ACTION_APP_ERROR);
        bug.putExtra(Intent.EXTRA_BUG_REPORT, report);
        bug.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (bug.resolveActivity(context.getPackageManager()) != null)
            context.startActivity(bug);
    } catch (Throwable exex) {
        Log.e(TAG, exex.toString() + "\n" + Log.getStackTraceString(exex));
    }
}

From source file:com.huison.DriverAssistant_Web.util.LoginHelper.java

/**
 * JSONString//ww w .  j a va 2  s .com
 * 
 * @param jsonObject
 * @param key
 * @return
 * @throws JSONException
 */
private static final String getJSONValueAsString(JSONObject jsonObject, String key) throws JSONException {
    try {
        return String.valueOf(jsonObject.get(key));
    } catch (JSONException e) {
        Log.e("getJSONValueAsString", Log.getStackTraceString(e));
        return "";
    }
}

From source file:com.smp.musicspeed.MainActivity.java

private void cleanUp() {
    if (!isMyServiceRunning(this, PlayFileService.class) && !isMyServiceRunning(this, FileWriterService.class)
            && !isMyServiceRunning(this, HardPathService.class)) {
        try {//ww  w  .j  a  va2 s.com
            FileMethods.deleteTempDir();
        } catch (Exception e) {
            logException(Log.getStackTraceString(e));
            e.printStackTrace();
        }

    }
}

From source file:org.alfresco.mobile.android.application.providers.storage.StorageAccessDocumentsProvider.java

@Override
public Cursor queryRecentDocuments(String rootId, String[] projection) throws FileNotFoundException {
    // Log.v(TAG, "queryRecentDocuments" + rootId);

    final DocumentFolderCursor recentDocumentsCursor = new DocumentFolderCursor(
            resolveDocumentProjection(projection));
    Uri uri = DocumentsContract.buildRecentDocumentsUri(mAuthority, rootId);
    final EncodedQueryUri cUri = new EncodedQueryUri(rootId);

    Boolean active = mLoadingUris.get(uri);

    if (active != null) {
        for (Entry<String, Node> nodeEntry : nodesIndex.entrySet()) {
            addNodeRow(recentDocumentsCursor, nodeEntry.getValue());
        }/*from  www  .  j  a v  a  2 s  . c  o  m*/
        if (!active) {
            // loading request is finished and refreshed
            mLoadingUris.remove(uri);
        }
    }

    if (active == null) {
        new StorageProviderAsyncTask(uri, recentDocumentsCursor, true) {
            @Override
            protected Void doInBackground(Void... params) {
                try {
                    checkSession(cUri);
                    GregorianCalendar calendar = new GregorianCalendar();
                    calendar.add(Calendar.DAY_OF_YEAR, -7);
                    String formatedDate = DateUtils.format(calendar);
                    List<Node> nodes = session.getServiceRegistry().getSearchService()
                            .search(String.format(QUERY_RECENT, formatedDate), SearchLanguage.CMIS);

                    for (Node node : nodes) {
                        nodesIndex.put(NodeRefUtils.getVersionIdentifier(node.getIdentifier()), node);
                    }

                } catch (Exception e) {
                    exception = null;
                    Log.w(TAG, Log.getStackTraceString(e));
                }
                return null;
            }
        }.execute();
    }
    return recentDocumentsCursor;
}

From source file:it.geosolutions.geocollect.android.core.mission.PendingMissionListActivity.java

@Override
protected void onDestroy() {
    super.onDestroy();
    // In the tablet layout the map can be visible within this activity
    if (this.mapViewManager != null) {
        this.mapViewManager.destroyMapViews();
    }/*w w w.  j  ava  2s. c om*/
    if (this.spatialiteDatabase != null) {
        try {
            this.spatialiteDatabase.close();
            Log.v(TAG, "Spatialite Database Closed");
        } catch (jsqlite.Exception e) {
            Log.e(TAG, Log.getStackTraceString(e));
        }
    }
}

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

/**************************************************************************/

@SuppressWarnings("unused")
private static void openIABPurchaseSucceeded(String json) {
    try {/*ww  w. java  2  s  .co m*/
        JSONObject purchase = new JSONObject(json);
        if (Teak.isDebug) {
            Log.d(LOG_TAG, "OpenIAB purchase succeeded: " + purchase.toString(2));
        }

        if (Teak.appStore != null && Teak.appStore.ignorePluginPurchaseEvents()) {
            if (Teak.isDebug) {
                Log.d(LOG_TAG, "OpenIAB callback ignored, store purchase reporting is auto-magical.");
            }
        } else {
            JSONObject originalJson = new JSONObject(purchase.getString("originalJson"));
            purchaseSucceeded(originalJson);
        }
    } catch (Exception e) {
        Log.e(LOG_TAG, Log.getStackTraceString(e));
        Teak.sdkRaven.reportException(e);
    }
}

From source file:android_network.hetnet.vpn_service.ActivityLog.java

private void handleExportPCAP(final Intent data) {
    new AsyncTask<Object, Object, Throwable>() {
        @Override//ww w .j ava  2 s  . c  om
        protected Throwable doInBackground(Object... objects) {
            OutputStream out = null;
            FileInputStream in = null;
            try {
                // Stop capture
                ServiceSinkhole.setPcap(false, ActivityLog.this);

                Uri target = data.getData();
                if (data.hasExtra("org.openintents.extra.DIR_PATH"))
                    target = Uri.parse(target + "/netguard.pcap");
                Log.i(TAG, "Export PCAP URI=" + target);
                out = getContentResolver().openOutputStream(target);

                File pcap = new File(getDir("data", MODE_PRIVATE), "netguard.pcap");
                in = new FileInputStream(pcap);

                int len;
                long total = 0;
                byte[] buf = new byte[4096];
                while ((len = in.read(buf)) > 0) {
                    out.write(buf, 0, len);
                    total += len;
                }
                Log.i(TAG, "Copied bytes=" + total);

                return null;
            } catch (Throwable ex) {
                Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                return ex;
            } finally {
                if (out != null)
                    try {
                        out.close();
                    } catch (IOException ex) {
                        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                    }
                if (in != null)
                    try {
                        in.close();
                    } catch (IOException ex) {
                        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                    }

                // Resume capture
                SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ActivityLog.this);
                if (prefs.getBoolean("pcap", false))
                    ServiceSinkhole.setPcap(true, ActivityLog.this);
            }
        }

        @Override
        protected void onPostExecute(Throwable ex) {
            if (ex == null)
                Toast.makeText(ActivityLog.this, R.string.msg_completed, Toast.LENGTH_LONG).show();
            else
                Toast.makeText(ActivityLog.this, ex.toString(), Toast.LENGTH_LONG).show();
        }
    }.execute();
}