android-assets

How to read a text file from assets in Android Studio?

梦想与她 提交于 2019-12-23 04:42:17
问题 I have may wifi2.txt file in my assets file directory in Android Studio. However, I keep getting a NULLPointException when I try to access it. My code is below: (Thanks so much in advance) //CSV FILE READING File file = null; try { FileInputStream is = new FileInputStream(file); try { BufferedReader reader = new BufferedReader(new InputStreamReader(getAssets().open("wifi2.txt"))); String line; Log.e("Reader Stuff",reader.readLine()); while ((line = reader.readLine()) != null) { Log.e("code"

how to get file path of asset folder in android

﹥>﹥吖頭↗ 提交于 2019-12-20 12:11:04
问题 I have an Android application used to transfer the .png image from asset folder of Android application to my local server. I need to get the path of image in asset folder, pls refer my code below, String stringPath = "android.resource//"+getPackageName()+"/raw/sample/logout.png"; File f = new File(stringPath); If I use the above code I got "File not found exception". So how to take image path in asset folder? 回答1: You could put your mp3 files at : res/raw folder. MediaPlayer mediaPlayer =

Reading file from assets directory throws FileNotFoundException

☆樱花仙子☆ 提交于 2019-12-18 12:20:13
问题 I'm trying to read in a text file of a bunch of words that I want to use for a word game I am writing. This list is stored in the assets directory and is a txt file. But, whenever I attempt to open it, it throws an exception. List<String>wordList = new ArrayList<String>(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getAssets().open("wordlist.txt"))); //throwing a FileNotFoundException? String word; while((word=br.readLine()) != null) wordList.add(word); /

Android icon generator for actionbar and notification not working (grey shape)

心不动则不痛 提交于 2019-12-18 10:43:26
问题 I found this Asset Studio to generate icons. It works fine for the launcher icon but for action bar or notification icons it is not working. I put in my png file and want to generate the icons, but Asset Studio is only generating gray circles. Is there another tool to generate action bar and notification icons? 回答1: You can use a tool for creating generic icons in Asset Studio: https://romannurik.github.io/AndroidAssetStudio/icons-generic.html. To get it look like ActionBar Icon, you should

how to get file name and file count from asset folder in Android?

喜欢而已 提交于 2019-12-18 07:24:59
问题 I have some media file in my asset folder. I want to get all media files names and files count from my asset folder. 回答1: A little googling might have helped you! try this: AssetManager assetManager = getAssets(); String[] files = assetManager.list("your_folder_name_inside_assets"); List<String> it = new LinkedList<String>(Arrays.asList(files)); 来源: https://stackoverflow.com/questions/22861480/how-to-get-file-name-and-file-count-from-asset-folder-in-android

Android: Playing an Asset Sound Using WebView

限于喜欢 提交于 2019-12-17 16:11:23
问题 I am trying to play a sound from the assets folder when a user clicks on an tag on my application's WebView. I found that I can use a new class extending WebViewClient to detect the extension of a link and if it is an mp3 file it can play it via the default Audio Player. But I want it to play within the activity without starting a new activity. I used the following links as references: Sound in Webview and Error creating MediaPlayer with Uri or file in assets But it didn't work. I tried using

Failed to save image from app assets folder to Gallery Folder in Android?

半腔热情 提交于 2019-12-13 20:50:54
问题 I have written this code its saving image in specified folder name but i want to save this image in Gallery/Specified FolderName/Image .Can someone please help me ..... CODE: saveImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub saveImage(getBitmapFromAsset("save_fatwa.jpg"), "save_fatwa.jpg"); } }); private Bitmap getBitmapFromAsset(String strName) { AssetManager assetManager = getAssets(); InputStream istr =

Can't copy pre-created db from assets

六月ゝ 毕业季﹏ 提交于 2019-12-13 08:36:19
问题 android cant copy my pre create db from assets , the old db still exist in data/data/packagename/dabases, i want to change old db with new one ive tried to change this.getReadableDatabase(); into SQLiteDatabse db = this.getReadabledatabase() if (db.isOpen()){ db.close(); } public void createDatabase(){ boolean dbExist = checkDatabase(); if(!dbExist){ this.getReadableDatabase(); SQl try { copyDatabase(); }catch (IOException e){ Log.e(this.getClass().toString(),"eror kopi"); throw new Error(

Loading files within android

大憨熊 提交于 2019-12-13 04:39:45
问题 Android seems to make life pretty easy for loading resources of certain types. Once I leave the beaten path a little bit, it seems less helpful. I can load in images, sounds and other objects from the assets folder if and only if they are of certain types. If I try to load a binary file of my own format, I get a less than helpful 'file not found' exception, even though listing the directory shows that it is clearly there. I've tried using the following methods to read a binary file of a

Playing a video from memory

拟墨画扇 提交于 2019-12-12 18:27:20
问题 Is it possible to play a video directly from memory, using the MemoryFile class? I tried: AssetFileDescriptor afd = getResources().openRawResourceFd(videoResId); InputStream is = getResources().openRawResource(videoResId); // BufferedReader br = new BufferedReader(new InputStreamReader(is)); try { memoryFile = new MemoryFile("myvideo", (int) afd.getDeclaredLength()); byte[] buffer = new byte[8192]; int bytesRead, totalBytesRead = 0; while ((bytesRead = is.read(buffer)) != -1) { memoryFile