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.android.mms.transaction.RetrieveTransaction.java

private void sendNotifyRespInd(int status) {
    MmsLog.i(MmsApp.TXN_TAG, "RetrieveTransaction: sendNotifyRespInd()");
    // Create the M-NotifyResp.ind
    try {// w  ww. j a  va 2  s. c o m
        NotificationInd notificationInd = (NotificationInd) PduPersister.getPduPersister(mContext).load(mUri);

        NotifyRespInd notifyRespInd = null;
        try {
            notifyRespInd = new NotifyRespInd(PduHeaders.CURRENT_MMS_VERSION,
                    notificationInd.getTransactionId(), status);
        } catch (InvalidHeaderValueException ex) {
            ex.printStackTrace();
            return;
        }
        byte[] datas = new PduComposer(mContext, notifyRespInd).make();
        File pduFile = createPduFile(datas, NOTIFY_RESP_NAME + mUri.getLastPathSegment());
        if (pduFile == null) {
            return;
        }

        SmsManager manager = SmsManager.getSmsManagerForSubscriptionId(mSubId);
        /*
        Intent intent = new Intent(TransactionService.ACTION_TRANSACION_PROCESSED);
        intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId);
        // intent.putExtra(TransactionBundle.URI, mUri.toString());
        PendingIntent sentIntent = PendingIntent.getBroadcast(mContext, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
            */
        // Pack M-NotifyResp.ind and send it
        Uri pduFileUri = FileProvider.getUriForFile(mContext, MMS_FILE_PROVIDER_AUTHORITIES, pduFile);
        if (MmsConfig.getNotifyWapMMSC()) {
            manager.sendMultimediaMessage(mContext, pduFileUri, mContentLocation, null, null);
        } else {
            manager.sendMultimediaMessage(mContext, pduFileUri, null, null, null);
        }
    } catch (Throwable t) {
        Log.e(TAG, Log.getStackTraceString(t));
    }
}

From source file:org.alfresco.mobile.android.application.fragments.config.ConfigMenuEditorFragment.java

private JSONObject saveConfiguration() {
    JSONObject configuration = new JSONObject();
    try {// www .  j  ava  2 s. co  m
        // INFO
        JSONObject info = new JSONObject();
        info.put(ConfigConstants.SCHEMA_VERSION_VALUE, 0.2);
        info.putOpt(ConfigConstants.CONFIG_VERSION_VALUE, 0.1);
        configuration.put(ConfigTypeIds.INFO.value(), info);

        // PROFILES
        JSONObject profiles = new JSONObject();
        JSONObject defaultProfile = new JSONObject();
        defaultProfile.put(ConfigConstants.DEFAULT_VALUE, true);
        defaultProfile.putOpt(ConfigConstants.LABEL_ID_VALUE, "Custom Default");
        defaultProfile.putOpt(ConfigConstants.ROOTVIEW_ID_VALUE, "views-menu-default");
        profiles.put("default", defaultProfile);
        configuration.put(ConfigTypeIds.PROFILES.value(), profiles);

        // VIEW GROUPS
        JSONArray viewGroupsArray = new JSONArray();
        JSONObject defaultMenu = new JSONObject();
        defaultMenu.putOpt(ConfigConstants.ID_VALUE, "views-menu-default");
        defaultMenu.putOpt(ConfigConstants.LABEL_ID_VALUE, getString(R.string.menu_view));

        // Items
        JSONArray items = new JSONArray();
        for (int i = 0; i < adapter.getCount(); i++) {
            items.put(((ViewConfigImpl) menuConfigItems.get(i)).toJson());
        }

        defaultMenu.putOpt(ConfigConstants.ITEMS_VALUE, items);
        viewGroupsArray.put(defaultMenu);

        configuration.put(ConfigTypeIds.VIEW_GROUPS.value(), viewGroupsArray);

        // SAVE TO DEVICE
        OutputStream sourceFile = null;
        try {
            File configFolder = AlfrescoStorageManager.getInstance(getActivity()).getCustomFolder(account);
            File configFile = new File(configFolder, ConfigConstants.CONFIG_FILENAME);

            sourceFile = new FileOutputStream(configFile);
            sourceFile.write(configuration.toString().getBytes("UTF-8"));
            sourceFile.close();

            // Send Event
            ConfigManager.getInstance(getActivity()).loadAndUseCustom(account);
            EventBusManager.getInstance().post(new ConfigManager.ConfigurationMenuEvent(accountId));
        } catch (Exception e) {
            Log.w(TAG, Log.getStackTraceString(e));
        } finally {
            org.alfresco.mobile.android.api.utils.IOUtils.closeStream(sourceFile);
        }
    } catch (JSONException e) {
        Log.w(TAG, Log.getStackTraceString(e));
    }
    return configuration;
}

From source file:net.olejon.mdapp.InteractionsCardsActivity.java

private void search(final String string, boolean cache) {
    try {/*  w w  w .j  ava 2  s .c o m*/
        RequestQueue requestQueue = Volley.newRequestQueue(mContext);

        String apiUri = getString(R.string.project_website_uri) + "api/1/interactions/?search="
                + URLEncoder.encode(string.toLowerCase(), "utf-8");

        if (!cache)
            requestQueue.getCache().remove(apiUri);

        JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(apiUri, new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                mProgressBar.setVisibility(View.GONE);
                mSwipeRefreshLayout.setRefreshing(false);

                if (response.length() == 0) {
                    mSwipeRefreshLayout.setVisibility(View.GONE);
                    mNoInteractionsLayout.setVisibility(View.VISIBLE);
                } else {
                    if (mTools.isTablet()) {
                        int spanCount = (response.length() == 1) ? 1 : 2;

                        mRecyclerView.setLayoutManager(
                                new StaggeredGridLayoutManager(spanCount, StaggeredGridLayoutManager.VERTICAL));
                    }

                    mRecyclerView.setAdapter(new InteractionsCardsAdapter(mContext, mProgressBar, response));

                    ContentValues contentValues = new ContentValues();
                    contentValues.put(InteractionsSQLiteHelper.COLUMN_STRING, string);

                    SQLiteDatabase sqLiteDatabase = new InteractionsSQLiteHelper(mContext)
                            .getWritableDatabase();

                    sqLiteDatabase.delete(InteractionsSQLiteHelper.TABLE, InteractionsSQLiteHelper.COLUMN_STRING
                            + " = " + mTools.sqe(string) + " COLLATE NOCASE", null);
                    sqLiteDatabase.insert(InteractionsSQLiteHelper.TABLE, null, contentValues);

                    sqLiteDatabase.close();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                mProgressBar.setVisibility(View.GONE);
                mSwipeRefreshLayout.setRefreshing(false);

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

                finish();

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

        requestQueue.add(jsonArrayRequest);
    } catch (Exception e) {
        Log.e("InteractionsCards", Log.getStackTraceString(e));
    }
}

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

public static boolean isEnabled(PackageInfo info, Context context) {
    int setting;/* ww w .j a va  2  s  .c o m*/
    try {
        PackageManager pm = context.getPackageManager();
        setting = pm.getApplicationEnabledSetting(info.packageName);
    } catch (IllegalArgumentException ex) {
        setting = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
        Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }
    if (setting == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)
        return info.applicationInfo.enabled;
    else
        return (setting == PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
}

From source file:com.listomate.activities.AccountsActivity.java

/**
 * Retrieves the authorization cookie associated with the given token. This
 * method should only be used when running against a production appengine
 * backend (as opposed to a dev mode server).
 *//*from   w  w  w. j a va2s.  co  m*/
private String getAuthCookie(String authToken) {
    try {
        // Get SACSID cookie
        DefaultHttpClient client = new DefaultHttpClient();
        String continueURL = Setup.PROD_URL;
        URI uri = new URI(Setup.PROD_URL + "/_ah/login?continue=" + URLEncoder.encode(continueURL, "UTF-8")
                + "&auth=" + authToken);
        HttpGet method = new HttpGet(uri);
        final HttpParams getParams = new BasicHttpParams();
        HttpClientParams.setRedirecting(getParams, false);
        method.setParams(getParams);

        HttpResponse res = client.execute(method);
        Header[] headers = res.getHeaders("Set-Cookie");
        if (res.getStatusLine().getStatusCode() != 302 || headers.length == 0) {
            return null;
        }

        for (Cookie cookie : client.getCookieStore().getCookies()) {
            if (AUTH_COOKIE_NAME.equals(cookie.getName())) {
                return AUTH_COOKIE_NAME + "=" + cookie.getValue();
            }
        }
    } catch (IOException e) {
        Log.w(TAG, "Got IOException " + e);
        Log.w(TAG, Log.getStackTraceString(e));
    } catch (URISyntaxException e) {
        Log.w(TAG, "Got URISyntaxException " + e);
        Log.w(TAG, Log.getStackTraceString(e));
    }

    return null;
}

From source file:net.olejon.mdapp.MedicationActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home: {
        NavUtils.navigateUpFromSameTask(this);
        return true;
    }/*from w  w  w  . j  a  v  a  2s  . c  om*/
    case R.id.medication_menu_find_in_text: {
        if (mToolbarSearchLayout.getVisibility() == View.VISIBLE) {
            mWebView.findNext(true);

            mInputMethodManager.hideSoftInputFromWindow(mToolbarSearchEditText.getWindowToken(), 0);
        } else {
            mToolbarSearchLayout.setVisibility(View.VISIBLE);
            mToolbarSearchEditText.requestFocus();

            mInputMethodManager.showSoftInput(mToolbarSearchEditText, 0);
        }

        if (!mTools.getSharedPreferencesBoolean("WEBVIEW_FIND_IN_TEXT_HIDE_TIP_DIALOG")) {
            new MaterialDialog.Builder(mContext)
                    .title(getString(R.string.main_webview_find_in_text_tip_dialog_title))
                    .content(getString(R.string.main_webview_find_in_text_tip_dialog_message))
                    .positiveText(getString(R.string.main_webview_find_in_text_tip_dialog_positive_button))
                    .onPositive(new MaterialDialog.SingleButtonCallback() {
                        @Override
                        public void onClick(@NonNull MaterialDialog materialDialog,
                                @NonNull DialogAction dialogAction) {
                            mTools.setSharedPreferencesBoolean("WEBVIEW_FIND_IN_TEXT_HIDE_TIP_DIALOG", true);
                        }
                    }).contentColorRes(R.color.black).positiveColorRes(R.color.dark_blue).show();
        }

        return true;
    }
    case R.id.medication_menu_favorite: {
        favorite();
        return true;
    }
    case R.id.medication_menu_interactions: {
        Intent intent = new Intent(mContext, InteractionsActivity.class);
        intent.putExtra("search", medicationName);
        startActivity(intent);
        return true;
    }
    case R.id.medication_menu_poisonings: {
        Intent intent = new Intent(mContext, PoisoningsCardsActivity.class);
        intent.putExtra("search", medicationName);
        startActivity(intent);
        return true;
    }
    case R.id.medication_menu_atc: {
        Intent intent = new Intent(mContext, AtcCodesActivity.class);
        intent.putExtra("code", medicationAtcCode);
        startActivity(intent);
        return true;
    }
    case R.id.medication_menu_note: {
        if (mTools.getSharedPreferencesString("NOTES_PIN_CODE").equals("")) {
            new MaterialDialog.Builder(mContext).title(getString(R.string.medication_note_dialog_title))
                    .content(getString(R.string.medication_note_dialog_message))
                    .positiveText(getString(R.string.medication_note_dialog_positive_button))
                    .negativeText(getString(R.string.medication_note_dialog_negative_button))
                    .onPositive(new MaterialDialog.SingleButtonCallback() {
                        @Override
                        public void onClick(@NonNull MaterialDialog materialDialog,
                                @NonNull DialogAction dialogAction) {
                            Intent intent = new Intent(mContext, NotesActivity.class);
                            startActivity(intent);
                        }
                    }).contentColorRes(R.color.black).positiveColorRes(R.color.dark_blue)
                    .negativeColorRes(R.color.black).show();
        } else {
            Intent intent = new Intent(mContext, NotesEditActivity.class);
            intent.putExtra("title", medicationName);
            startActivity(intent);
        }

        return true;
    }
    case R.id.medication_menu_manufacturer: {
        getManufacturer();
        return true;
    }
    case R.id.medication_menu_slv: {
        try {
            Intent intent = new Intent(mContext, MainWebViewActivity.class);
            intent.putExtra("title", getString(R.string.medication_menu_slv));
            intent.putExtra("uri",
                    "http://www.legemiddelverket.no/Legemiddelsoek/Sider/default.aspx?searchquery="
                            + URLEncoder.encode(medicationName, "utf-8"));
            startActivity(intent);
        } catch (Exception e) {
            Log.e("MedicationActivity", Log.getStackTraceString(e));
        }

        return true;
    }
    case R.id.medication_menu_print: {
        if (mViewPagerPosition == 0) {
            mTools.printDocument(MedicationNlhFragment.WEBVIEW, medicationName);
        } else {
            mTools.printDocument(MedicationFelleskatalogenFragment.WEBVIEW, medicationName);
        }

        return true;
    }
    default: {
        return super.onOptionsItemSelected(item);
    }
    }
}

From source file:net.olejon.mdapp.ClinicalTrialsCardsActivity.java

private void search(final String string, boolean cache) {
    try {/*from w  ww  . j a v a 2 s . c om*/
        RequestQueue requestQueue = Volley.newRequestQueue(mContext);

        String apiUri = getString(R.string.project_website_uri) + "api/1/clinicaltrials/?search="
                + URLEncoder.encode(string.toLowerCase(), "utf-8");

        if (!cache)
            requestQueue.getCache().remove(apiUri);

        JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(apiUri, new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                mProgressBar.setVisibility(View.GONE);
                mSwipeRefreshLayout.setRefreshing(false);

                if (response.length() == 0) {
                    mSwipeRefreshLayout.setVisibility(View.GONE);
                    mNoClinicalTrialsLayout.setVisibility(View.VISIBLE);
                } else {
                    if (mTools.isTablet()) {
                        int spanCount = (response.length() == 1) ? 1 : 2;

                        mRecyclerView.setLayoutManager(
                                new StaggeredGridLayoutManager(spanCount, StaggeredGridLayoutManager.VERTICAL));
                    }

                    mRecyclerView.setAdapter(new ClinicalTrialsCardsAdapter(mContext, response));

                    ContentValues contentValues = new ContentValues();
                    contentValues.put(ClinicalTrialsSQLiteHelper.COLUMN_STRING, string);

                    SQLiteDatabase sqLiteDatabase = new ClinicalTrialsSQLiteHelper(mContext)
                            .getWritableDatabase();

                    sqLiteDatabase.delete(ClinicalTrialsSQLiteHelper.TABLE,
                            ClinicalTrialsSQLiteHelper.COLUMN_STRING + " = " + mTools.sqe(string)
                                    + " COLLATE NOCASE",
                            null);
                    sqLiteDatabase.insert(ClinicalTrialsSQLiteHelper.TABLE, null, contentValues);

                    sqLiteDatabase.close();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                mProgressBar.setVisibility(View.GONE);
                mSwipeRefreshLayout.setRefreshing(false);

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

                finish();

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

        jsonArrayRequest.setRetryPolicy(new DefaultRetryPolicy(30000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

        requestQueue.add(jsonArrayRequest);
    } catch (Exception e) {
        Log.e("ClinicalTrialsCards", Log.getStackTraceString(e));
    }
}

From source file:org.opendatakit.logging.WebLoggerImpl.java

public void printStackTrace(Throwable e) {
    //e.printStackTrace();
    ByteArrayOutputStream ba = new ByteArrayOutputStream();
    PrintStream w;/*  w  w w  . j a  va2  s  .  c  om*/
    try {
        w = new PrintStream(ba, false, "UTF-8");
        e.printStackTrace(w);
        w.flush();
        w.close();
        log(ba.toString("UTF-8"));
    } catch (UnsupportedEncodingException ignored) {
        // error if it ever occurs
        throw new IllegalStateException("unable to specify UTF-8 Charset!");
    } catch (IOException e1) {
        Log.e(TAG, Log.getStackTraceString(e1), e1);
    }
}

From source file:org.apache.cordova.plugins.Actionable.java

private void updateTabs(final JSONArray tabs) {
    for (int i = 0; i < tabs.length(); i++) {
        try {//from  www .  j  a  v  a2s  . c  o m
            JSONObject mi = tabs.getJSONObject(i);
            final Actionable action = Actionable.fromJSON(mi);
            final TabListener self = this;

            mDroidGap.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Tab t = mBar.newTab();
                    t.setText(action.getTitle());
                    t.setTabListener(self);
                    t.setTag(action.getCallbackId());
                    if (action.getIcon() != null) {
                        t.setIcon(action.getIcon());
                    }
                    mBar.addTab(t);

                    if (action.isSelected()) {
                        mBar.selectTab(t);
                    }
                }
            });

        } catch (Exception e) {
            Log.v("Cambie", Log.getStackTraceString(e));
        }
    }

    if (tabs.length() > 0) {
        mDroidGap.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                mBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
            }
        });
    }
}

From source file:com.dm.wallpaper.board.fragments.WallpapersFragment.java

private void getWallpapers(boolean refreshing) {
    final String wallpaperUrl = getActivity().getResources().getString(R.string.wallpaper_json);
    mGetWallpapers = new AsyncTask<Void, Void, Boolean>() {

        List<Wallpaper> wallpapers;

        @Override/*from w w w.  j av a2 s . c  o  m*/
        protected void onPreExecute() {
            super.onPreExecute();
            if (refreshing) {
                mSwipe.setRefreshing(true);
                WallpaperBoardListener listener = (WallpaperBoardListener) getActivity();
                listener.onWallpapersChecked(null);
            } else {
                mProgress.setVisibility(View.VISIBLE);
            }

            wallpapers = new ArrayList<>();

            if (mPopupBubble.getVisibility() == View.VISIBLE) {
                AnimationHelper.hide(mPopupBubble).start();
            }
        }

        @Override
        protected Boolean doInBackground(Void... voids) {
            while (!isCancelled()) {
                try {
                    Thread.sleep(1);
                    Database database = Database.get(getActivity());
                    if (!refreshing && database.getWallpapersCount() > 0) {
                        wallpapers = database.getFilteredWallpapers();
                        return true;
                    }

                    URL url = new URL(wallpaperUrl);
                    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                    connection.setConnectTimeout(15000);

                    if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
                        InputStream stream = connection.getInputStream();
                        WallpaperJson wallpapersJson = LoganSquare.parse(stream, WallpaperJson.class);

                        if (wallpapersJson == null)
                            return false;
                        if (refreshing) {
                            if (database.getWallpapersCount() > 0) {
                                wallpapers = database.getWallpapers();
                                List<Wallpaper> newWallpapers = new ArrayList<>();
                                for (WallpaperJson wallpaper : wallpapersJson.getWallpapers) {
                                    newWallpapers.add(new Wallpaper(wallpaper.name, wallpaper.author,
                                            wallpaper.thumbUrl, wallpaper.url, wallpaper.category));
                                }

                                List<Wallpaper> intersection = (List<Wallpaper>) ListHelper
                                        .intersect(newWallpapers, wallpapers);
                                List<Wallpaper> deleted = (List<Wallpaper>) ListHelper.difference(intersection,
                                        wallpapers);
                                List<Wallpaper> newlyAdded = (List<Wallpaper>) ListHelper
                                        .difference(intersection, newWallpapers);

                                database.deleteCategories();
                                database.addCategories(wallpapersJson.getCategories);
                                database.deleteWallpapers(deleted);
                                database.addWallpapers(newlyAdded);

                                Preferences.get(getActivity())
                                        .setAvailableWallpapersCount(database.getWallpapersCount());
                                wallpapers = database.getFilteredWallpapers();
                                return true;
                            }
                        }

                        if (database.getWallpapersCount() > 0)
                            database.deleteWallpapers();

                        database.addCategories(wallpapersJson.getCategories);
                        database.addWallpapers(wallpapersJson);
                        wallpapers = database.getFilteredWallpapers();
                        return true;
                    }
                    return false;
                } catch (Exception e) {
                    LogUtil.e(Log.getStackTraceString(e));
                    return false;
                }
            }
            return false;
        }

        @Override
        protected void onPostExecute(Boolean aBoolean) {
            super.onPostExecute(aBoolean);
            if (refreshing)
                mSwipe.setRefreshing(false);
            mProgress.setVisibility(View.GONE);
            if (aBoolean) {
                setHasOptionsMenu(true);
                mAdapter = new WallpapersAdapter(getActivity(), wallpapers, false, false);
                mRecyclerView.setAdapter(mAdapter);

                try {
                    TapIntroHelper.showWallpapersIntro(getActivity(), mRecyclerView);
                } catch (Exception e) {
                    LogUtil.e(Log.getStackTraceString(e));
                }
            } else {
                Toast.makeText(getActivity(), R.string.connection_failed, Toast.LENGTH_LONG).show();
            }
            mGetWallpapers = null;
            showPopupBubble();
        }
    }.execute();
}