android-assets

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("

NullPointerException trying to access a String resource

一笑奈何 提交于 2019-12-01 17:54:41
I have the following /res/values/uris.xml <?xml version="1.0" encoding="utf-8"?> <resources> <string name="bladder">blahblah</string> </resources> I am accessing it in code: private String bladderUrl= getString(R.string.bladder); But it is returning null. I'm not sure why? My guess you placed bladderUrl smth like this: public class YourActivity extends Activity { private String bladderUrl = getString(R.string.bladder); @Override public void onCreate(Bundle savedInstanceState) { ... However you need to do smth like this: public class YourActivity extends Activity { private String bladderUrl;

NullPointerException trying to access a String resource

冷暖自知 提交于 2019-12-01 16:14:16
问题 I have the following /res/values/uris.xml <?xml version="1.0" encoding="utf-8"?> <resources> <string name="bladder">blahblah</string> </resources> I am accessing it in code: private String bladderUrl= getString(R.string.bladder); But it is returning null. I'm not sure why? 回答1: My guess you placed bladderUrl smth like this: public class YourActivity extends Activity { private String bladderUrl = getString(R.string.bladder); @Override public void onCreate(Bundle savedInstanceState) { ...

Referencing image in assets from HTML not working

故事扮演 提交于 2019-12-01 07:37:23
I'm trying to display an image in a WebView in an Android app. The image exists in the assets folder of my Android project. The HTML is programmatically built and has this image ref in it: The HTML is loaded into the WebView using: webView.loadDataWithBaseURL( urlStr, htmlText, "text/html", "utf-8", urlStr ); urlStr = a base url needed to find other resources. htmlText = the programmatically generate HTML The WebView loads the HTML fine, but the image is displayed as "missing". I have verified that the image exists at that location in the assets. Nevertheless it does not appear in the WebView.

How to access assets folder in my android app?

吃可爱长大的小学妹 提交于 2019-12-01 06:49:13
I'm writing at a little project for a friend. A notecard application. My plan is to put the notecards in an xml format so i can import and export them easily. I located the xml files at the assets/xml/mynotecard.xml folder but i just can't manage to get access to this file. Whenever i try to interpret the xml file (will be put to it's on class later) i get the exception with: test.xml is not a file. This is an extract of my code: public class NotecardProActivity extends Activity { List<String> xmlFiles; public ArrayList<File> xmlFileList; XMLInterpreter horst; /** Called when the activity is

How to access assets folder in my android app?

限于喜欢 提交于 2019-12-01 05:22:22
问题 I'm writing at a little project for a friend. A notecard application. My plan is to put the notecards in an xml format so i can import and export them easily. I located the xml files at the assets/xml/mynotecard.xml folder but i just can't manage to get access to this file. Whenever i try to interpret the xml file (will be put to it's on class later) i get the exception with: test.xml is not a file. This is an extract of my code: public class NotecardProActivity extends Activity { List<String

Referencing image in assets from HTML not working

不想你离开。 提交于 2019-12-01 05:01:17
问题 I'm trying to display an image in a WebView in an Android app. The image exists in the assets folder of my Android project. The HTML is programmatically built and has this image ref in it: The HTML is loaded into the WebView using: webView.loadDataWithBaseURL( urlStr, htmlText, "text/html", "utf-8", urlStr ); urlStr = a base url needed to find other resources. htmlText = the programmatically generate HTML The WebView loads the HTML fine, but the image is displayed as "missing". I have

Problem while opening Asset File with the help of Content Provider

北慕城南 提交于 2019-12-01 04:13:33
My requirement is to open one app's Asset file from another app via content provider.(I am exposing that file with ContentProvider implementation) I am able to open few files and read, but while opening some files I am getting exception. Please find the implementation for opening Asset File. @Override public AssetFileDescriptor openAssetFile(Uri uri, String mode) throws FileNotFoundException { AssetManager am = getContext().getAssets(); String file_name = uri.getLastPathSegment(); if(file_name == null) throw new FileNotFoundException(); AssetFileDescriptor afd = null; try { afd = am.openFd

What is an Android Asset?

我与影子孤独终老i 提交于 2019-12-01 03:24:00
I'm doing my first steps in Android development, and came across the term Asset . As far as I understand it, an Asset is simply a file that is not being parsed or referensed as a resource. Is there a more accurate definition of the term? In which scenarios should I use an Asset in my application? Assets provide a way to include arbitrary files like text, xml, fonts, music, and video in your application. If you try to include these files as "resources", Android will process them into its resource system and you will not be able to get the raw data. If you want to access data untouched, Assets