Ответы пользователя по тегу Android
  • Как получить программно путь к физической SD card на Android устройствах?

    @Evgenij_Popovich
    Использую команду mount. Решение найдено на stackoverflow

    /**
         * Returns possible external sd card path. Solution taken from here
         * http://stackoverflow.com/a/13648873/527759
         * 
         * @return
         */
        public static Set<String> getExternalMounts() {
            final Set<String> out = new HashSet<String>();
            try {
                String reg = ".*vold.*(vfat|ntfs|exfat|fat32|ext3|ext4).*rw.*";
                StringBuilder sb = new StringBuilder();
                try {
                    final Process process = new ProcessBuilder().command("mount")
                            .redirectErrorStream(true).start();
                    process.waitFor();
                    final InputStream is = process.getInputStream();
                    final byte[] buffer = new byte[1024];
                    while (is.read(buffer) != -1) {
                        sb.append(new String(buffer));
                    }
                    is.close();
                } catch (final Exception e) {
                    e.printStackTrace();
                }
                // parse output
                final String[] lines = sb.toString().split("\n");
                for (String line : lines) {
                    if (!line.toLowerCase(Locale.ENGLISH).contains("asec")) {
                        if (line.matches(reg)) {
                            String[] parts = line.split(" ");
                            for (String part : parts) {
                                if (part.startsWith("/"))
                                    if (!part.toLowerCase(Locale.ENGLISH).contains("vold")) {
                                        CommonUtils.debug(TAG, "Found path: " + part);
                                        out.add(part);
                                    }
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                error(TAG, ex);
            }
            return out;
        }
    }
    Ответ написан
    Комментировать
  • Частый VMDebug.startGC() при создании bitmap?

    @Evgenij_Popovich
    промазал
    Ответ написан
    Комментировать
  • Частый VMDebug.startGC() при создании bitmap?

    @Evgenij_Popovich
    1. Зачем декодировать сразу все 100 картинок и держать их в памяти, а не по мере появления их на экране?
    2. Используйте опции декодирования, чтобы картинки не резервировали память на долго

    final BitmapFactory.Options options = new BitmapFactory.Options();
     
    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
     
    // #302 added to reduce amount of OutOfMemory errors
    options.inDither = false; // Disable Dithering mode
    options.inPurgeable = true; // Tell to gc that whether it needs
                                // free memory, the Bitmap can be
                                // cleared
    options.inInputShareable = true; // Which kind of reference will
                                     // be used to recover the Bitmap
                                     // data after being clear, when
                                     // it will be used in the future
    options.inTempStorage = new byte[32 * 1024];


    3. Потребляемую память можно посмотреть на вкладке Heap view. На Ваших скринах этого не видно
    Ответ написан