android-file

android - filter assetManager.list files by type

南笙酒味 提交于 2019-12-01 19:16:14
I want to get a list of my html files from a specific directory in my assets. There is the code >> private List<String> ListDir(String directory) { List<String> result = new ArrayList<String>(); AssetManager am = getActivity().getAssets(); String[] files=null; try { files = am.list(directory); } catch (IOException e) { e.printStackTrace(); } fileList.clear(); for (String file : files) { result.add(file); } return result; } How can I filter my files in just .html ones? Just use endsWith(".xml") . for (String file : files) { if(file.toLowerCase().endsWith(".xml")){ result.add(file); } } 来源:

android - filter assetManager.list files by type

青春壹個敷衍的年華 提交于 2019-12-01 18:40:40
问题 I want to get a list of my html files from a specific directory in my assets. There is the code >> private List<String> ListDir(String directory) { List<String> result = new ArrayList<String>(); AssetManager am = getActivity().getAssets(); String[] files=null; try { files = am.list(directory); } catch (IOException e) { e.printStackTrace(); } fileList.clear(); for (String file : files) { result.add(file); } return result; } How can I filter my files in just .html ones? 回答1: Just use endsWith("

How can I save my bitmap correctly for second time?

微笑、不失礼 提交于 2019-12-01 04:26:43
I want to save my bitmap to cache directory. I use this code: try { File file_d = new File(dir+"screenshot.jpg"); @SuppressWarnings("unused") boolean deleted = file_d.delete(); } catch (Exception e) { // TODO: handle exception } imagePath = new File(dir+"screenshot.jpg"); FileOutputStream fos; try { fos = new FileOutputStream(imagePath); bitmap.compress(CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); } catch (FileNotFoundException e) { Log.e("GREC", e.getMessage(), e); } catch (IOException e) { Log.e("GREC", e.getMessage(), e); } } it s working fine. But if I want to save different

How to get path to Storage directory in android

核能气质少年 提交于 2019-12-01 01:12:41
Is there any method to get /storage/ directory. I tried with Environment.getExternalStorageDirectory() but it returns /storage/emulated/0 i know i can use file.getParent() but for some reason i cant use that. I just want a straight path to /storage/ directory using some function... Thanks in advance. You can't and should not access that directory normally . But it seems you need more control on storage locations are available to your device. For that you can use this, public List<String> getStorageDirectories() { // Final set of paths final ArrayList<String> finalPaths = new ArrayList<String>(

How to Get Absolute Path in Android for File?

为君一笑 提交于 2019-11-30 21:09:14
btnimport.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent fileintent = new Intent(Intent.ACTION_GET_CONTENT); fileintent.setType("*/*"); try { startActivityForResult(fileintent, requestcode); } catch (ActivityNotFoundException e) { } } });` I'm trying to import sky.csv file in my Android application. But, when I select file, I'd get: IO Exception : open failed: ENOENT (No such file or directory) I will check path in: LOG > content://com.android.externalstorage.documents/document/38F0-D5E4%3ADCIM%2Fsky.csv i'm using this method for getting path `

can't create folder programmatically on external storage - Android

人走茶凉 提交于 2019-11-30 20:55:17
问题 This is my code: boolean success = false; Log.d(TAG, Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_PICTURES + "/myFolder" ); myFolder = new File( Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_PICTURES + "/myFolder" ); if( myFolder.exists() ){ Log.d(TAG, "FOLDER EXISTS"); }else{ success = myFolder.mkdir(); if( success ){ // Do something on success } else { // Do something else on failure throw new RuntimeException("File Error in writing new

How to capture/record clip from Video URL in Android and save to phone

喜你入骨 提交于 2019-11-30 18:51:13
In Android, is it possible to record a short clip (ex: an arbitrary 5-10 seconds in the video) from a Video URL (ex: http://www.test.com/video.mp4 )? For example, I'd like to stream a video (from url) in an Activity and allow the ability to capture/record a short clip from it. Perhaps, allow the user to record an arbitrary Start/End time from the video. If so, is there an API to accomplish this? If not, is there an Android library to support this? Please provide a sample code solution for this. Kiril Aleksandrov You can see this link. In short your server has to support downloading. If it does

Why do I need the WRITE_EXTERNAL_STORAGE permission with getExternalCacheDir() on Android Lollipop?

丶灬走出姿态 提交于 2019-11-30 15:02:16
问题 My app writes (and reads) cache files to the getExternalCacheDir() location. Before Android Lollipop (API 21) I've been using this permission with success: <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" /> The maxSdkVersion is there because this permission shouldn't be needed after API v18: http://developer.android.com/reference/android/Manifest.permission.html#WRITE_EXTERNAL_STORAGE But on Android Lollipop (5.0) I'm getting an access

Android: how to get list of all preference xml's for my app and read them?

元气小坏坏 提交于 2019-11-30 14:09:57
问题 how to get list of all application preferences for application, 1. I am saving shared preference in this manner 2. I know that they are in data/data/app_packagename/shared_prefs 3. THE PROBLEM: But how to get list of all preference xml files in a spinner and read each preference, i searched in SO, but i did not found any help regarding this, how to do read all preference xml files in my application directory and access the preferences? P.S: I am aware of SharedPreference.getAll(); , will be

Why do I need the WRITE_EXTERNAL_STORAGE permission with getExternalCacheDir() on Android Lollipop?

ε祈祈猫儿з 提交于 2019-11-30 13:03:24
My app writes (and reads) cache files to the getExternalCacheDir() location. Before Android Lollipop (API 21) I've been using this permission with success: <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" /> The maxSdkVersion is there because this permission shouldn't be needed after API v18: http://developer.android.com/reference/android/Manifest.permission.html#WRITE_EXTERNAL_STORAGE But on Android Lollipop (5.0) I'm getting an access permission like so (with my log output to show the actual path used): 11-19 13:01:59.257 4462-4541/com