android-assets

How to access a file from asset/raw directory

六眼飞鱼酱① 提交于 2019-11-28 07:07:40
问题 with this below code i'm trying to access the file which is stored in asset/raw folder, but getting null and E/ERR: file:/android_asset/raw/default_book.txt (No such file or directory) error, my code is: private void implementingDefaultBook() { String filePath = Uri.parse("file:///android_asset/raw/default_book.txt").toString(); File file = new File(filePath); try { FileInputStream stream = new FileInputStream(file); } catch (Exception e) { e.printStackTrace(); Log.e("ERR ", e.getMessage());

Updating prepopulated database in Android

大兔子大兔子 提交于 2019-11-27 21:45:25
I lost last 3 hours trying to do this. Im making an app that will ship with a DB filled with populated tables that would not change on clients devices. I managed to do this by putting it in the assets folder and copying it as a stream of bytes to the appropriate data folder on the phone. Problem is when I wish to update the database, I cant get it to work. I delete the DB in data folder on phone (from code), but copying the new database always fails, or the copied DB has the appropriate size but no tables in it. How to do this? Or is there a simpler way? Can I open DB directly from assets (it

Accessing a font under assets folder from XML file in Android

偶尔善良 提交于 2019-11-27 21:04:57
I am trying to do a application-wide font change and creating a style file to do so. In this file (below) I just want to change typeface value of TextAppearance style of Android. <?xml version="1.0" encoding="utf-8"?> <resources> <style name="NightRiderFont" parent="@android:style/TextAppearance"> <item name="android:typeface"> /***help need here***/ </item> </style> </resources> However font is in "assets/fonts/". How can I access this font, so I can use that style as a theme to get rid of changing all TextViews by hand programatically. As summary: How can I access 'a file from assets folder'

How to read a text file from “assets” directory as a string?

坚强是说给别人听的谎言 提交于 2019-11-27 18:12:49
问题 I have a file in my assets folder... how do I read it? Now I'm trying: public static String readFileAsString(String filePath) throws java.io.IOException{ StringBuffer fileData = new StringBuffer(1000); BufferedReader reader = new BufferedReader( new FileReader(filePath)); char[] buf = new char[1024]; int numRead=0; while((numRead=reader.read(buf)) != -1){ String readData = String.valueOf(buf, 0, numRead); fileData.append(readData); buf = new char[1024]; } reader.close(); return fileData

Android - Copy files from assets to /data/data folder

南楼画角 提交于 2019-11-27 16:23:43
问题 I need to use some files in my app. They are kept in asset folder. I saw discussions on SO, where the files are being copied from asset folder, to /data/data/ on the internal storage, and then being used. I get the code, but what I do not get is, what is the need to copy the assets to internal storage ? If anybody has experience with this, help ! 回答1: One reason that just popped up for me is when using existing C/C++ code with NDK that requires a path to a file and you don't want to modify

Android: copy database from asset folder, but only get an empty file

我是研究僧i 提交于 2019-11-27 15:11:55
问题 guys, I have the problem when copying database from local assets folder to /data/data/package_name/databases directory. As I use the http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/ tutorial to do it, I can only get an empty file. I quoted the part of copyDataBase() method and there is no difference. Every time the app start, it will create the directory and empty database. So is there any way to make the copyDataBase() work? Thank you very much!! 回答1: I

Save a (.txt) file to the Assets Folder in Android?

 ̄綄美尐妖づ 提交于 2019-11-27 13:46:19
问题 How to write to .txt file in assets folder. How to get path assets folder ? 回答1: You can't. The assets folder is read-only at runtime. Pick a different location to save your data, see Data Storage for more information. 回答2: The path of assets folder is file:///android_asset But this is read-only. The assets folder is like folders res, src, gen, etc. These are all useful to provide different files as input to build system to generate APK file for your app. All these are read-only while your

Opening a File from assets folder in android

怎甘沉沦 提交于 2019-11-27 08:39:38
I have a .gif file inside the assets folder like this assets/Files/android.gif. when I try to open the file it throws an exception at the second line AssetManager mngr=getAssets(); InputStream is2=mngr.open("Files/android.gif"); so Is it that I'm trying to open an image file despite that the same code works if I try to open a text file ? what can be the problem here. These Lines are working perfectly-- InputStream assetInStream=null; try { assetInStream=getAssets().open("icon.png"); Bitmap bit=BitmapFactory.decodeStream(assetInStream); img.setImageBitmap(bit); } catch (IOException e) { e

DB File in Assets Folder. Will it be Updated?

旧巷老猫 提交于 2019-11-27 07:17:50
I'm new to the Android SQLite whole thing. This is what I have: I have db.sqlite in my assets folder. The intent of the db is to READ ONLY. The user will not write to it. When the app gets updated, the db.sqlite will be replaced be a new db (I'll delete the old file from the project and add the new one). What I'm concerned about is: Will the old db file gets deleted? (that's what I want; replacing the old one with the new one) Why ask? Because when I debug my app, each time I update the db file, I need to uninstall the app from the device in order to force the update. Will the users need to do

Android multiple screen design

旧城冷巷雨未停 提交于 2019-11-27 06:19:29
问题 I understand there is plenty of documentation about designing for multiple screen support in Android. and I have read the Android guide here as well as a number of similar questions such as this However I'm still a little confused as to how I should implement it for my application. I plan to target the following device configurations Am I correct in thinking I will need to structure the project layouts as follows: Medium density Normal screens HVGA 320x480 (160dpi): res/layout-mdpi (320 x 480