android – MediaPlayer setDataSource, better to use path or FileDescriptor?-ThrowExceptions

Exception or error: Let’s say I have a full path to a file. Which is the better approach to loading that file into a MediaPlayer? String filePath = “somepath/somefile.mp3”; mediaPlayer.setDataSource(filePath); OR String filePath = “somepath/somefile.mp3”; File file = new File(filePath); FileInputStream inputStream = new FileInputStream(file); mediaPlayer.setDataSource(inputStream.getFD()); inputStream.close(); Does it matter? Simply using the path seems …

How to open local PDF file in WebView in Android?-ThrowExceptions

Exception or error: I want to open local (SD card) PDF file in a WebView. I already tried this: webview = (WebView) findViewById(R.id.webview); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setPluginsEnabled(true); webview.getSettings().setAllowFileAccess(true); File file = new File(Environment.getExternalStorageDirectory() + “/test.pdf”); final Uri uri = Uri.fromFile(file); webview.loadUrl(uri.toString()); But it’s still not opening it, so let me know how I can open a PDF …

android – Gradle signing app with packageRelease “specified for property 'signingConfig.storeFile' does not exist”-ThrowExceptions

Exception or error: I am trying to test an app with Build Variant in release mode in Android Studio with a project using Gradle. build.gradle: (omitted dependencies and repositories) android { apply plugin: ‘android’ compileSdkVersion 19 buildToolsVersion “19.0.0” defaultConfig { minSdkVersion 11 targetSdkVersion 16 versionCode 1 versionName “1.0” } signingConfigs { release { storeFile file(“release.jks”) …

Where should I place font file in Android resources?-ThrowExceptions

Exception or error: Where in res folder should I put my font file (TTF)? How to solve: You can create the font in asset folder (i.e asset/fonts/roboto.ttf). Then, create an appropriate class for your TextView: // RobotoFont class package com.my.font; public class RobotoFont extends TextView { public RobotoFont(Context context, AttributeSet attrs, int defStyle) { super(context, …

android – How to access files from assets folder during tests execution?-ThrowExceptions

Exception or error: How to access files from assets folder during unit tests execution? My project is build using Gradle, I use Robolectric to run tests. It seems like gradle is being recognizing the assets: This is how I’m struggling to read the file: public String readFileFromAssets(String fileName) throws IOException { InputStream stream = getClass().getClassLoader().getResourceAsStream(“assets/” …

bitmapfactory – Android: decodeFile always returns null for file in internal storage-ThrowExceptions

Exception or error: I have a file saved locally into the application’s private storage. I have verified it exists, however whenever I call BitmapFactory.decodeFile it always returns null. If I save the file as a resource and use ImageView.setImageResource, it always shows up fine. What is the problem? Here is the snippet: filename = “test.png”; …