Skip to content Skip to sidebar Skip to footer

Is There A Way To Get A Url To A Specific File In Android Expansion File?

I am building a PhoneGap application, which contains large audio and video files. In Android the media files should be in an expansion file to keep the application size under the G

Solution 1:

I found myself a way to do this through a content provider. I got a hint about the Content Provider from question android play movie inside expansion file, although in that question the URL was not used to start an external application.

We need a ContentProvider class that extends Google's APEZProvider:

publicclassZipFileContentProviderextendsAPEZProvider {
    @OverridepublicStringgetAuthority() {
        return"com.example.expansionexperiment.provider";
    }
}

And it needs to be added to Manifest and exported:

<providerandroid:exported="true"android:name="com.example.expansionexperiment.ZipFileContentProvider"android:authorities="com.example.expansionexperiment.provider" />

The authority in the manifest and in getAuthority() must be the same.

Now we can create a Uri to the file inside Expansion File:

// Filename inside my expansion fileStringfilename="video/video.mp4";
StringuriString="content://com.example.expansionexperiment.provider" +  File.separator + filename;
Uriuri= Uri.parse(uriString);

// Start video view intentIntentintent=newIntent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "video/*");
startActivity(intent);

The content provider provides now access to the zip file and the files within just with the URL.

However, PhoneGap's Media plugin does not support content providers, because if the URL does not start with http, it inserts "/sdcard/" in front of the URL. (!!!) Therefore, to play audio files through the zip content provider, you will need to write your own audio plugin.

Post a Comment for "Is There A Way To Get A Url To A Specific File In Android Expansion File?"