Opening a File from assets folder in android

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.printStackTrace(); } finally { if(assetInStream!=null) assetInStream.close(); } If your image is very big then you should scale your image before decoding it into Bitmap. See How to display large image efficiently

Loading existing .html file with android WebView

ok, that was my very stupid mistake. I post the answer here just in case someone has the same problem. The correct path for files stored in assets folder is file:///android_asset/* (with no “s” for assets folder which i was always thinking it must have a “s”). And, mWebView.loadUrl(“file:///android_asset/myfile.html”); works under all API levels. I … Read more

Play audio file from the assets directory

player.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength()); Your version would work if you had only one file in the assets directory. The asset directory contents are not actually ‘real files’ on disk. All of them are put together one after another. So, if you do not specify where to start and how many bytes to read, the player will read up … Read more

Read a pdf file from assets folder

Try this public class SampleActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); CopyReadAssets(); } private void CopyReadAssets() { AssetManager assetManager = getAssets(); InputStream in = null; OutputStream out = null; File file = new File(getFilesDir(), “abc.pdf”); try { in = assetManager.open(“abc.pdf”); out = openFileOutput(file.getName(), Context.MODE_WORLD_READABLE); copyFile(in, out); in.close(); in = null; … Read more