summaryrefslogtreecommitdiffstats
path: root/samples/ApiDemos/src/com/example/android/apis/content/FileProvider.java
diff options
context:
space:
mode:
Diffstat (limited to 'samples/ApiDemos/src/com/example/android/apis/content/FileProvider.java')
-rw-r--r--samples/ApiDemos/src/com/example/android/apis/content/FileProvider.java17
1 files changed, 11 insertions, 6 deletions
diff --git a/samples/ApiDemos/src/com/example/android/apis/content/FileProvider.java b/samples/ApiDemos/src/com/example/android/apis/content/FileProvider.java
index f26bcdaf4..63d891d09 100644
--- a/samples/ApiDemos/src/com/example/android/apis/content/FileProvider.java
+++ b/samples/ApiDemos/src/com/example/android/apis/content/FileProvider.java
@@ -111,14 +111,19 @@ public class FileProvider extends ContentProvider
}
@Override
- public AssetFileDescriptor openAssetFile(Uri uri, String mode) throws FileNotFoundException {
+ public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
// Try to open an asset with the given name.
try {
- InputStream is = getContext().getAssets().open(uri.getPath());
- // Start a new thread that pipes the stream data back to the caller.
- return new AssetFileDescriptor(
- openPipeHelper(uri, null, null, is, this), 0,
- AssetFileDescriptor.UNKNOWN_LENGTH);
+ String path = uri.getPath();
+ int off = path.indexOf('/', 1);
+ if (off < 0 || off >= (path.length()-1)) {
+ throw new FileNotFoundException("Unable to open " + uri);
+ }
+ int cookie = Integer.parseInt(path.substring(1, off));
+ String assetPath = path.substring(off+1);
+ AssetFileDescriptor asset = getContext().getAssets().openNonAssetFd(cookie, assetPath);
+ return new ParcelFileDescriptor(openPipeHelper(uri, null, null,
+ asset.createInputStream(), this));
} catch (IOException e) {
FileNotFoundException fnf = new FileNotFoundException("Unable to open " + uri);
throw fnf;