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.maxwen.wallpaper.board.fragments.WallpaperSearchFragment.java

private void getWallpapers() {
    mGetWallpapers = new AsyncTask<Void, Void, Boolean>() {

        List<Wallpaper> wallpapers;

        @Override/*from ww w.j  ava2s .  c  om*/
        protected void onPreExecute() {
            super.onPreExecute();
            wallpapers = new ArrayList<>();
        }

        @Override
        protected Boolean doInBackground(Void... voids) {
            while (!isCancelled()) {
                try {
                    Thread.sleep(1);
                    Database database = new Database(getActivity());
                    // TODO should search use filter?
                    //wallpapers = database.getFilteredWallpapers();
                    wallpapers = database.getWallpapers();
                    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) {
                mAdapter = new WallpapersAdapter(getActivity(), wallpapers, false, true);
                mRecyclerView.setAdapter(mAdapter);
                onSpanCountChanged();
                if (mSearchView != null)
                    mSearchView.requestFocus();
                SoftKeyboardHelper.openKeyboard(getActivity());
            }
        }
    }.execute();
}

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

@Nullable
public static byte[] getBitmapByte(@NonNull Drawable drawable) {
    try {//from w w  w. j  a  v  a  2 s .co  m
        Bitmap bitmap;
        if (drawable instanceof LayerDrawable) {
            bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                    Bitmap.Config.ARGB_8888);
            drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
            drawable.draw(new Canvas(bitmap));
        } else {
            bitmap = ((BitmapDrawable) drawable).getBitmap();
        }
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 10, stream);
        return stream.toByteArray();
    } catch (Exception | OutOfMemoryError e) {
        LogUtil.e(Log.getStackTraceString(e));
    }
    return null;
}

From source file:com.tmall.wireless.tangram3.support.SimpleClickSupport.java

public void onClick(View targetView, BaseCell cell, int eventType, Map<String, Object> params) {
    if (optimizedMode) {
        defaultClick(targetView, cell, eventType);
    } else {/*w w w .j a v  a  2 s.  com*/
        if (mOnClickMethods.isEmpty()) {
            findClickMethods(this.getClass().getMethods());
        }
        List<Class<?>> classes = lookupCellTypes(targetView.getClass());
        for (Class clz : classes) {
            if (clz.equals(View.class)) {
                continue;
            }
            if (mOnClickMethods.containsKey(clz)) {
                OnClickMethod onClickMethod = mOnClickMethods.get(clz);
                try {
                    if (onClickMethod.paramLength == 3) {
                        onClickMethod.method.invoke(this, targetView, cell, eventType);
                        return;
                    } else if (onClickMethod.paramLength == 4) {
                        onClickMethod.method.invoke(this, targetView, cell, eventType, params);
                        return;
                    }
                } catch (Exception e) {
                    LogUtils.e(TAG, "Invoke onClick method error: " + Log.getStackTraceString(e), e);
                }
            }
        }
        defaultClick(targetView, cell, eventType);
    }
}

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

private void resetDonations() {
    try {//w w w  .  jav  a 2s. co m
        final Bundle purchasesBundle = mIInAppBillingService.getPurchases(3, getPackageName(), "inapp", null);

        final int responseCode = purchasesBundle.getInt("RESPONSE_CODE");

        if (responseCode == 0) {
            final ArrayList<String> purchaseDataList = purchasesBundle
                    .getStringArrayList("INAPP_PURCHASE_DATA_LIST");

            if (purchaseDataList != null) {
                for (String purchaseData : purchaseDataList) {
                    consumeDonation(new JSONObject(purchaseData).getString("purchaseToken"));
                }
            }

            mTools.showToast(getString(R.string.donate_reset_success), 0);
        } else {
            mTools.showToast(getString(R.string.donate_something_went_wrong), 1);
        }
    } catch (Exception e) {
        mTools.showToast(getString(R.string.donate_something_went_wrong), 1);

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

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

public static void login(final BaseActivity activity, final String username, final String password,
        final boolean autoLogin) {
    Log.i(TAG, "call login func:" + username + "/" + password);
    ctx = activity;//from  ww w  . j av  a2s  .c om
    UmengEventSender.sendEvent(activity, UmengEventTypes.login);
    final ProgressDialog pd = new ProgressDialog(activity);
    pd.setMessage(activity.getString(R.string.logging_wait));
    pd.show();
    AsyncHttpClient client = activity.getAsyncHttpClient();
    RequestParams params = new RequestParams();
    try {
        JSONObject p = new JSONObject();
        p.put("mobile", username);
        p.put("password", password);
        p.put("method", "login");
        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.i(TAG, "request parameters: " + p.toString());
        String data = Util.DesJiaMi(p.toString(), "czxms520");
        Log.i(TAG, "post data:" + data);
        params.put("data", data);
    } catch (Exception e) {
        activity.showMessageBox(activity.getString(R.string.wrong_profile));
        Log.e(TAG, e.getMessage());
        e.printStackTrace();
        return;
    }
    // params.put("xml", BaseActivity.getXML(map));
    Log.i(TAG, "AsyncHttpClient post:" + BaseActivity.REQUESTURL);
    client.post(BaseActivity.REQUESTURL, params, new JsonHttpResponseHandler() {
        @Override
        public void onDispatchSuccess(int statusCode, Header[] headers, String result) {
            Log.i(TAG, "onDispatchSuccess: " + result);
            pd.dismiss();
            try {
                Log.i(TAG, "decrypting...");
                result = Util.decrypt(result, "czxms520");
                Log.v(TAG, "result decrypted :" + result);
                JSONObject jo = new JSONObject(result);
                String code = jo.getString("code");
                String msg = getJSONValueAsString(jo, "message");
                if (code.equals("0")) {
                    jo = new JSONObject(jo.getString("data"));
                    // 
                    String loginTime = getJSONValueAsString(jo, "LastLogin");
                    // 
                    String lastLoginTime = getJSONValueAsString(jo, "LastLogin");
                    // SESSIONKEY
                    /*
                     * String sessionKey = getJSONValueAsString( jo,
                     * "sessionkey");
                     */
                    // 
                    String urlHead = getJSONValueAsString(jo, "PhotoUrl");
                    String photoUrl = getJSONValueAsString(jo, "PhotoUrl");
                    String phone = getJSONValueAsString(jo, "Mobile");
                    Boolean vip = false;
                    if (String.valueOf(jo.getInt("Vip")).equals("1")) {
                        vip = true;
                    } else {
                        vip = false;
                    }
                    Env.isLogined = BaseActivity.isLogined = true;
                    Log.v(TAG, ":1");
                    activity.markLogin(phone, phone, password, autoLogin, "", loginTime, lastLoginTime, vip);
                    if (!photoUrl.equals("")) {
                        String finalHeadUrl = URLDecoder.decode(photoUrl, "utf-8");
                        BaseActivity.setUserHeadUrl(finalHeadUrl);
                        BaseActivity.setUserHeadDrawable(null);
                    } else {
                        BaseActivity.setUserHeadUrl("");
                        BaseActivity.setUserHeadDrawable(null);
                    }
                    // sendMsg(ConfigActivity.thiz,0);
                    //  start
                    HomeActivity.now_mobile = phone;
                    //  end
                    // 
                    // 
                    Log.v("", "kk" + phone);
                    LoginActivity.instance.finish();
                    Util.saveFile(phone, Environment.getExternalStorageDirectory() + "/xmsphone.txt");
                    SharedPreferences.Editor sharedata = activity.getSharedPreferences("MyData", 0).edit();
                    sharedata.putString("isJZMM_czxms", "true");
                    sharedata.commit();
                    Log.i(TAG, ":2");
                    sendMsg(0);
                    sendMsg(ConfigActivity.thiz, 2);
                    activity.finish();
                } else {
                    Log.e(TAG, "server notify failed: error:" + msg);
                    LoginActivity.pw.setText("");
                    activity.showMessageBox(msg);
                }
            } catch (JSONException e) {
                Log.e(TAG, "login error" + Log.getStackTraceString(e));
                e.printStackTrace();
                activity.showMessageBox(activity.getText(R.string.server404));
            } catch (Exception e) {
                Log.e(TAG, Log.getStackTraceString(e));
                //e.printStackTrace();
                activity.showMessageBox(",.");
            }
        }

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

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

From source file:eu.faircode.netguard.ServiceJob.java

private static void submit(Rule rule, PersistableBundle bundle, Context context) {
    PackageManager pm = context.getPackageManager();
    JobScheduler scheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);

    // Get english application label
    String label = null;/* ww w  . ja va2s. c o  m*/
    try {
        Configuration config = new Configuration();
        config.setLocale(new Locale("en"));
        Resources res = pm.getResourcesForApplication(rule.info.packageName);
        res.updateConfiguration(config, res.getDisplayMetrics());
        label = res.getString(rule.info.applicationInfo.labelRes);
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
        CharSequence cs = rule.info.applicationInfo.loadLabel(pm);
        if (cs != null)
            label = cs.toString();
    }

    // Add application data
    bundle.putInt("uid", rule.info.applicationInfo.uid);
    bundle.putString("package", rule.info.packageName);
    bundle.putInt("version_code", rule.info.versionCode);
    bundle.putString("version_name", rule.info.versionName);
    bundle.putString("label", label);
    bundle.putInt("system", rule.system ? 1 : 0);
    try {
        bundle.putString("installer", pm.getInstallerPackageName(rule.info.packageName));
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
        bundle.putString("installer", null);
    }

    // Cancel overlapping jobs
    for (JobInfo pending : scheduler.getAllPendingJobs()) {
        String type = pending.getExtras().getString("type");
        if (type != null && type.equals(bundle.getString("type"))) {
            if (type.equals("rule")) {
                int uid = pending.getExtras().getInt("uid");
                if (uid == bundle.getInt("uid")) {
                    Log.i(TAG, "Canceling id=" + pending.getId());
                    scheduler.cancel(pending.getId());
                }
            } else if (type.equals("host")) {
                int uid = pending.getExtras().getInt("uid");
                int version = pending.getExtras().getInt("version");
                int protocol = pending.getExtras().getInt("protocol");
                String daddr = pending.getExtras().getString("daddr");
                int dport = pending.getExtras().getInt("dport");
                if (uid == bundle.getInt("uid") && version == bundle.getInt("version")
                        && protocol == bundle.getInt("protocol") && daddr != null
                        && daddr.equals(bundle.getString("daddr")) && dport == bundle.getInt("dport")) {
                    Log.i(TAG, "Canceling id=" + pending.getId());
                    scheduler.cancel(pending.getId());
                }
            }
        }
    }

    // Schedule job
    ComponentName serviceName = new ComponentName(context, ServiceJob.class);
    JobInfo job = new JobInfo.Builder(++id, serviceName).setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)
            .setMinimumLatency(Util.isDebuggable(context) ? 10 * 1000 : 60 * 1000).setExtras(bundle)
            .setPersisted(true).build();
    if (scheduler.schedule(job) == JobScheduler.RESULT_SUCCESS)
        Log.i(TAG, "Scheduled job=" + job.getId() + " success");
    else
        Log.e(TAG, "Scheduled job=" + job.getId() + " failed");
}

From source file:org.catrobat.catroid.ui.ScriptActivity.java

public void setupActionBar() {
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayShowTitleEnabled(true);
    String currentSprite = null;//  www.j a va2s  .c  o m
    try {
        currentSprite = ProjectManager.getInstance().getCurrentSprite().getName();
    } catch (NullPointerException nullPointerException) {
        Log.e(TAG, Log.getStackTraceString(nullPointerException));
        finish();
    }
    actionBar.setTitle(currentSprite);
}

From source file:fr.cmoatoto.multishare.receiver.NanoHTTPDReceiver.java

/**
 * Override this to customize the server.
 * <p>//w ww.  j av  a 2s.c  om
 * 
 * (By default, this delegates to serveFile() and allows directory listing.)
 * 
 * @param uri
 *            Percent-decoded URI without parameters, for example "/index.cgi"
 * @param method
 *            "GET", "POST" etc.
 * @param parms
 *            Parsed, percent decoded parameters from URI and, in case of POST, data.
 * @param header
 *            Header entries, percent decoded
 * @param inetAddress
 * @return HTTP response, see class Response for details
 */
public Response serve(String uri, String method, Properties header, Properties parms, Properties files,
        InetAddress inetAddress) {
    myOut.println(method + " '" + uri + "' " + inetAddress.toString());

    Enumeration e = header.propertyNames();
    String element = null;
    myOut.println("URI: " + uri);
    String value = null;
    String mimeType = null;
    String extension = null;

    while (e.hasMoreElements()) {
        element = (String) e.nextElement();
        myOut.println("  HDR: '" + element + "' = '" + header.getProperty(element) + "'");
    }
    e = parms.propertyNames();
    while (e.hasMoreElements()) {
        element = (String) e.nextElement();

        myOut.println("  PRM: '" + element + "' = '" + parms.getProperty(element) + "'");
        if (element.equals("value")) {
            value = parms.getProperty(element);
            if (value.contains("http://remote_host:")) {
                value = value.replace("/remote_host", inetAddress.toString());
                myOut.println("  PRM REPLACED BY: '" + element + "' = '" + value + "'");
            }
        } else if (element.equals("mime")) {
            mimeType = parms.getProperty(element);
        } else if (element.equals("extension")) {
            extension = parms.getProperty(element);
        }

        if (value != null && mimeType != null) {
            if ("keyboard/key".equals(mimeType)) {
                try {
                    RemotedKeyboard.sendKeyEvent(mContext, Integer.parseInt(value));
                } catch (NumberFormatException e2) {
                    myOut.println(Log.getStackTraceString(e2));
                }
            } else {
                HttpServiceReceiver.show(mContext, value, mimeType, extension);
            }
        }
    }
    e = files.propertyNames();
    while (e.hasMoreElements()) {
        element = (String) e.nextElement();
        myOut.println("  UPLOADED: '" + value + "' = '" + files.getProperty(value) + "'");
    }

    final StringBuilder buf = new StringBuilder();
    for (Entry<Object, Object> kv : header.entrySet())
        buf.append(kv.getKey() + " : " + kv.getValue() + "\n");

    return new NanoHTTPDReceiver.Response(HTTP_OK, mimeType, uri);
}

From source file:org.maikelwever.droidpile.backend.ApiConnecter.java

public void storeInCache(String query, String data) {
    try {/*  w  ww.j a  v a  2 s .co  m*/
        List<DataCache> currentlyCached = new Select().from(DataCache.class).where("key = ?", query).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(query, data, new Date().getTime());
    object.save();
    Log.d("droidpile", "Stored request in cache.");
}

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

public static boolean isInternational(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1 && hasPhoneStatePermission(context)) {
        int dataSubId;
        try {//from w  ww.ja  v a  2  s. co m
            dataSubId = Settings.Global.getInt(context.getContentResolver(), "multi_sim_data_call", -1);
        } catch (Throwable ignored) {
            dataSubId = -1;
        }
        if (dataSubId >= 0) {
            SubscriptionManager sm = SubscriptionManager.from(context);
            SubscriptionInfo si = sm.getActiveSubscriptionInfo(dataSubId);
            if (si != null && si.getCountryIso() != null)
                try {
                    Method getNetworkCountryIso = tm.getClass().getMethod("getNetworkCountryIsoForSubscription",
                            int.class);
                    getNetworkCountryIso.setAccessible(true);
                    String networkCountryIso = (String) getNetworkCountryIso.invoke(tm, dataSubId);
                    Log.d(TAG, "SIM=" + si.getCountryIso() + " network=" + networkCountryIso);
                    return !si.getCountryIso().equals(networkCountryIso);
                } catch (Throwable ex) {
                    Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                    sendCrashReport(ex, context);
                }
        }
    }

    return (tm == null || tm.getSimCountryIso() == null
            || !tm.getSimCountryIso().equals(tm.getNetworkCountryIso()));
}