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.projecthdata.ehr.viewer.service.HDataSyncService.java

/**
 * Clears out all root and section data, retrieves the current root document
 * and atom feeds] , and adds their information to the database.
 *///www.j a  v  a 2  s .  c  o m
private void onSyncRoot() {
    prefs.edit().putString(Constants.PREF_ROOT_SYNC_STATE, SyncState.WORKING.toString()).commit();
    // TODO: check for connection, launch OAuth activity, resume sync
    try {
        Dao<RootEntry, Integer> rootDao = hDataOrmManager.getDatabaseHelper().getRootEntryDao();
        // clear out existing data
        for (RootEntry entry : rootDao.queryForAll()) {
            entry.getSectionMetadata().clear();
            rootDao.delete(entry);
        }
        // fetch new data and add it to the database
        // use the connection to get the root document
        Connection<HData> connection = connectionRepository.getPrimaryConnection(HData.class);

        RootOperations rootOperations = connection.getApi().getRootOperations();
        Root root = rootOperations.getRoot();
        for (Section section : root.getSections()) {
            processSection(rootOperations, section);
        }
    } catch (SQLException e) {
        e.printStackTrace();
        Log.e(TAG, Log.getStackTraceString(e));
    }
    prefs.edit().putString(Constants.PREF_ROOT_SYNC_STATE, SyncState.READY.toString()).commit();
}

From source file:org.alfresco.mobile.android.application.capture.VideoCapture.java

@Override
public boolean captureData() {
    if (hasDevice()) {
        try {//w  w  w.j  a v  a  2 s .  c o  m

            File folder = parentFolder;
            if (folder != null) {
                Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
                if (intent.resolveActivity(context.getPackageManager()) == null) {
                    AlfrescoNotificationManager.getInstance(context).showAlertCrouton(parentActivity,
                            context.getString(R.string.feature_disable));
                    return false;
                }

                payload = new File(folder.getPath(), createFilename("VID", "mp4"));

                intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(payload));
                intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
                // Represents a limit of 300Mb
                intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, 314572800L);

                parentActivity.startActivityForResult(intent, getRequestCode());
            } else {
                AlfrescoNotificationManager.getInstance(parentActivity)
                        .showLongToast(parentActivity.getString(R.string.sdinaccessible));
            }
        } catch (Exception e) {
            Log.d(TAG, Log.getStackTraceString(e));
            return false;
        }

        return true;
    } else {
        return false;
    }
}

From source file:com.example.minhttruong.parsedemo.base.MainAct.java

/**
 * add or replace new fragment with @FragOption
 * @param fm/* w w w.  ja  v  a2  s. c  om*/
 * @param fragOption
 * @param newFrag
 */
public void swapFrag(FragmentManager fm, FragOption fragOption, BaseFrag newFrag) {
    if (fragOption == null)
        return;
    if (fragOption.newFragClazz == null)
        return;
    Fragment frag = getSupportFragmentManager().findFragmentById(fragOption.placeHolderId);
    if (fragOption.newFragClazz.isInstance(frag))
        return;
    if (newFrag == null) {
        try {
            newFrag = fragOption.newFragClazz.newInstance();
        } catch (InstantiationException e) {
            newFrag = null;
            Log.e(TAG, Log.getStackTraceString(e));
        } catch (IllegalAccessException e) {
            newFrag = null;
            Log.e(TAG, Log.getStackTraceString(e));
        }
    }
    if (newFrag != null) {
        FragmentTransaction ft = fm.beginTransaction();
        if (fragOption.isAdd) {
            ft.add(fragOption.placeHolderId, newFrag, fragOption.tag);
        } else {
            ft.replace(fragOption.placeHolderId, newFrag, fragOption.tag);
        }
        if (fragOption.isAddToBackStack) {
            ft.addToBackStack(fragOption.tag);
        }
        ft.commit();
    }
}

From source file:edu.cloud.iot.reception.ocr.ScanLicense.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_scan_license);

    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction().add(R.id.container, new PlaceholderFragment()).commit();
    }/*from  w  w w .  jav a 2  s .  c o  m*/

    setUpCamera();
    try {
        // Bitmap compImg =
        // BitmapFactory.decodeFile(String.valueOf(Environment.getExternalStoragePublicDirectory((
        // Environment.DIRECTORY_PICTURES + "/IOT/veera01.jpg"))));
        // ByteArrayOutputStream bos = new ByteArrayOutputStream();
        // compImg.compress(Bitmap.CompressFormat.JPEG, 100, bos);
        // baseImageBytes = bos.toByteArray();
        // bos.flush();
        // bos.close();
        // Log.i("EDebug::baseImageBytes = ",""+baseImageBytes.length);
    } catch (Exception ex) {
        Log.e("EDebug::OnCreate Error - ",
                "Error::" + ex.getLocalizedMessage() + "::" + Log.getStackTraceString(ex));
    }
}

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

public AppConfiguration(@NonNull Context context) {
    // Teak App Id
    {/*  ww  w .  j  a  va  2  s.  co  m*/
        this.appId = Helpers.getStringResourceByName(TEAK_APP_ID, context);
        if (this.appId == null) {
            throw new RuntimeException("Failed to find R.string." + TEAK_APP_ID);
        }
    }

    // Teak API Key
    {
        this.apiKey = Helpers.getStringResourceByName(TEAK_API_KEY, context);
        if (this.apiKey == null) {
            throw new RuntimeException("Failed to find R.string." + TEAK_API_KEY);
        }
    }

    // Push Sender Id
    {
        // TODO: Check ADM vs GCM
        this.pushSenderId = Helpers.getStringResourceByName(TEAK_GCM_SENDER_ID, context);
        if (this.pushSenderId == null && Teak.isDebug) {
            Log.d(LOG_TAG, "R.string." + TEAK_GCM_SENDER_ID + " not present, push notifications disabled.");
        }
    }

    // Package Id
    {
        this.bundleId = context.getPackageName();
        if (this.bundleId == null) {
            throw new RuntimeException("Failed to get Bundle Id.");
        }
    }

    PackageManager packageManager = context.getPackageManager();
    if (packageManager == null) {
        throw new RuntimeException("Unable to get Package Manager.");
    }

    // App Version
    {
        int tempAppVersion = 0;
        try {
            tempAppVersion = packageManager.getPackageInfo(this.bundleId, 0).versionCode;
        } catch (Exception e) {
            Log.e(LOG_TAG, "Error getting App Version: " + Log.getStackTraceString(e));
        } finally {
            this.appVersion = tempAppVersion;
        }
    }

    // Get the installer package
    {
        this.installerPackage = packageManager.getInstallerPackageName(this.bundleId);
        if (this.installerPackage == null) {
            Log.e(LOG_TAG, "Installer package (Store) is null, purchase tracking disabled.");
        }
    }

    // Tell the Raven service about the app id
    try {
        Intent intent = new Intent(context, RavenService.class);
        intent.putExtra("appId", this.appId);
        ComponentName componentName = context.startService(intent);
        if (componentName == null) {
            Log.e(LOG_TAG,
                    "Unable to communicate with exception reporting service. Please add:\n\t<service android:name=\"io.teak.sdk.service.RavenService\" android:process=\":teak.raven\" android:exported=\"false\"/>\nTo the <application> section of your AndroidManifest.xml");
        } else if (Teak.isDebug) {
            Log.d(LOG_TAG,
                    "Communication with exception reporting service established: " + componentName.toString());
        }
    } catch (Exception e) {
        Log.e(LOG_TAG,
                "Error calling startService for exception reporting service: " + Log.getStackTraceString(e));
    }
}

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

public DeviceConfiguration(@NonNull final Context context, @NonNull AppConfiguration appConfiguration) {
    if (android.os.Build.VERSION.RELEASE == null) {
        this.platformString = "android_unknown";
    } else {//  w ww .j av a  2 s  .  co m
        this.platformString = "android_" + android.os.Build.VERSION.RELEASE;
    }

    // Preferences file
    {
        SharedPreferences tempPreferences = null;
        try {
            tempPreferences = context.getSharedPreferences(Teak.PREFERENCES_FILE, Context.MODE_PRIVATE);
        } catch (Exception e) {
            Log.e(LOG_TAG, "Error calling getSharedPreferences(). " + Log.getStackTraceString(e));
        } finally {
            this.preferences = tempPreferences;
        }

        if (this.preferences == null) {
            Log.e(LOG_TAG, "getSharedPreferences() returned null. Some caching is disabled.");
        }
    }

    // Device model/manufacturer
    // https://raw.githubusercontent.com/jaredrummler/AndroidDeviceNames/master/library/src/main/java/com/jaredrummler/android/device/DeviceName.java
    {
        this.deviceManufacturer = Build.MANUFACTURER == null ? "" : Build.MANUFACTURER;
        this.deviceModel = Build.MODEL == null ? "" : Build.MODEL;
        if (this.deviceModel.startsWith(Build.MANUFACTURER)) {
            this.deviceFallback = capitalize(Build.MODEL);
        } else {
            this.deviceFallback = capitalize(Build.MANUFACTURER) + " " + Build.MODEL;
        }
    }

    // Device id
    {
        String tempDeviceId = null;
        try {
            tempDeviceId = UUID.nameUUIDFromBytes(android.os.Build.SERIAL.getBytes("utf8")).toString();
        } catch (Exception e) {
            Log.e(LOG_TAG, "android.os.Build.SERIAL not available, falling back to Settings.Secure.ANDROID_ID. "
                    + Log.getStackTraceString(e));
        }

        if (tempDeviceId == null) {
            try {
                String androidId = Settings.Secure.getString(context.getContentResolver(),
                        Settings.Secure.ANDROID_ID);
                if (androidId.equals("9774d56d682e549c")) {
                    Log.e(LOG_TAG,
                            "Settings.Secure.ANDROID_ID == '9774d56d682e549c', falling back to random UUID stored in preferences.");
                } else {
                    tempDeviceId = UUID.nameUUIDFromBytes(androidId.getBytes("utf8")).toString();
                }
            } catch (Exception e) {
                Log.e(LOG_TAG,
                        "Error generating device id from Settings.Secure.ANDROID_ID, falling back to random UUID stored in preferences. "
                                + Log.getStackTraceString(e));
            }
        }

        if (tempDeviceId == null) {
            if (this.preferences != null) {
                tempDeviceId = this.preferences.getString(PREFERENCE_DEVICE_ID, null);
                if (tempDeviceId == null) {
                    try {
                        String prefDeviceId = UUID.randomUUID().toString();
                        SharedPreferences.Editor editor = this.preferences.edit();
                        editor.putString(PREFERENCE_DEVICE_ID, prefDeviceId);
                        editor.apply();
                        tempDeviceId = prefDeviceId;
                    } catch (Exception e) {
                        Log.e(LOG_TAG,
                                "Error storing random UUID, no more fallbacks. " + Log.getStackTraceString(e));
                    }
                }
            } else {
                Log.e(LOG_TAG,
                        "getSharedPreferences() returned null, unable to store random UUID, no more fallbacks.");
            }
        }

        this.deviceId = tempDeviceId;

        if (this.deviceId == null) {
            return;
        }
    }

    // Kick off GCM request
    if (this.preferences != null) {
        int storedAppVersion = this.preferences.getInt(PREFERENCE_APP_VERSION, 0);
        String storedGcmId = this.preferences.getString(PREFERENCE_GCM_ID, null);
        if (storedAppVersion == appConfiguration.appVersion && storedGcmId != null) {
            // No need to get a new one, so put it on the blocking queue
            if (Teak.isDebug) {
                Log.d(LOG_TAG, "GCM Id found in cache: " + storedGcmId);
            }
            this.gcmId = storedGcmId;
            displayGCMDebugMessage();
        }
    }

    this.gcm = new FutureTask<>(new RetriableTask<>(100, 2000L, new Callable<GoogleCloudMessaging>() {
        @Override
        public GoogleCloudMessaging call() throws Exception {
            return GoogleCloudMessaging.getInstance(context);
        }
    }));
    new Thread(this.gcm).start();

    if (this.gcmId == null) {
        registerForGCM(appConfiguration);
    }

    // Kick off Advertising Info request
    fetchAdvertisingInfo(context);
}

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

@Override
public boolean onStartJob(JobParameters params) {
    Log.i(TAG, "Start job=" + params.getJobId());

    new AsyncTask<JobParameters, Object, Object>() {

        @Override/*w w  w  . j  av a  2 s  .  c  om*/
        protected JobParameters doInBackground(JobParameters... params) {
            Log.i(TAG, "Executing job=" + params[0].getJobId());

            HttpsURLConnection urlConnection = null;
            try {
                String android_id = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
                JSONObject json = new JSONObject();

                json.put("device", Util.sha256(android_id, ""));
                json.put("product", Build.DEVICE);
                json.put("sdk", Build.VERSION.SDK_INT);
                json.put("country", Locale.getDefault().getCountry());

                json.put("netguard", Util.getSelfVersionCode(ServiceJob.this));
                try {
                    json.put("store", getPackageManager().getInstallerPackageName(getPackageName()));
                } catch (Throwable ex) {
                    Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                    json.put("store", null);
                }

                for (String name : params[0].getExtras().keySet())
                    json.put(name, params[0].getExtras().get(name));

                urlConnection = (HttpsURLConnection) new URL(cUrl).openConnection();
                urlConnection.setConnectTimeout(cTimeOutMs);
                urlConnection.setReadTimeout(cTimeOutMs);
                urlConnection.setRequestProperty("Accept", "application/json");
                urlConnection.setRequestProperty("Content-type", "application/json");
                urlConnection.setRequestMethod("POST");
                urlConnection.setDoInput(true);
                urlConnection.setDoOutput(true);

                OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream());
                out.write(json.toString().getBytes()); // UTF-8
                out.flush();

                int code = urlConnection.getResponseCode();
                if (code != HttpsURLConnection.HTTP_OK)
                    throw new IOException("HTTP " + code);

                InputStreamReader isr = new InputStreamReader(urlConnection.getInputStream());
                Log.i(TAG, "Response=" + Util.readString(isr).toString());

                jobFinished(params[0], false);

                if ("rule".equals(params[0].getExtras().getString("type"))) {
                    SharedPreferences history = getSharedPreferences("history", Context.MODE_PRIVATE);
                    history.edit().putLong(params[0].getExtras().getString("package") + ":submitted",
                            new Date().getTime()).apply();
                }

            } catch (Throwable ex) {
                Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                jobFinished(params[0], true);

            } finally {
                if (urlConnection != null)
                    urlConnection.disconnect();

                try {
                    Thread.sleep(1000);
                } catch (InterruptedException ignored) {
                }
            }

            return null;
        }
    }.execute(params);

    return true;
}

From source file:com.dm.wallpaper.board.activities.WallpaperBoardSplashActivity.java

private void prepareApp() {
    mPrepareApp = new AsyncTask<Void, Void, Boolean>() {
        @Override//from w  ww.  j  a  v  a 2 s.  c  om
        protected Boolean doInBackground(Void... voids) {
            while (!isCancelled()) {
                try {
                    Thread.sleep(500);
                    return true;
                } catch (Exception e) {
                    LogUtil.e(Log.getStackTraceString(e));
                    return false;
                }
            }
            return null;
        }

        @Override
        protected void onPostExecute(Boolean aBoolean) {
            super.onPostExecute(aBoolean);
            if (aBoolean) {
                mPrepareApp = null;

                startActivity(new Intent(WallpaperBoardSplashActivity.this, mMainActivity));
                overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
                finish();
            }
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

From source file:hku.fyp14017.blencode.transfers.CheckTokenTask.java

@Override
protected Boolean doInBackground(Void... arg0) {
    try {/*from ww  w.  j a  v a 2 s .  c o  m*/
        if (!Utils.isNetworkAvailable(fragmentActivity)) {
            exception = new WebconnectionException(WebconnectionException.ERROR_NETWORK,
                    "Network not available!");
            return false;
        }

        return ServerCalls.getInstance().checkToken(token, username);

    } catch (WebconnectionException webconnectionException) {
        Log.e(TAG, Log.getStackTraceString(webconnectionException));
        exception = webconnectionException;
    }
    return false;

}

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

public static void createGroup(String name) {
    WeiboParameters params = new WeiboParameters();
    params.put("name", name);

    try {//from   ww w  .j a va 2s.  c  om
        request(Constants.FRIENDSHIPS_GROUPS_CREATE, params, HTTP_POST);
    } catch (Exception e) {
        if (DEBUG) {
            Log.e(TAG, "Cannot create group");
            Log.e(TAG, Log.getStackTraceString(e));
        }
    }
}