My apk version code is version 3. with it I am using main expansion file which was loaded with apk version code 1 (file name is similar to main.1.ex.etc.eg.obb). The expansion file downloads fine on a device.
The expansion file has media file, so I using APEZProvider
from the Google Zip Expansion Library to play it with VideoView
.
Calling VideoView.start()
causes an Nullpointer exception.
What I have found so far:
In APEZProvider.initIfNecessary()
returns Main expansion file version as 3 instead of 1. Thus trying to open ZipResourceFile
(mAPKExtensionFile) returns null. APEZProvider.openAssetFile()
causes NullPointerException
as mAPKExtensionFile
is null
.
Relevant code from APEZProvider
class in Google Zip Expansion Library:
private boolean initIfNecessary() {
if ( !mInit ) {
Context ctx = getContext();
PackageManager pm = ctx.getPackageManager();
ProviderInfo pi = pm.resolveContentProvider(getAuthority(), PackageManager.GET_META_DATA);
PackageInfo packInfo;
try {
packInfo = pm.getPackageInfo(ctx.getPackageName(), 0);
} catch (NameNotFoundException e1) {
e1.printStackTrace();
return false;
}
int patchFileVersion;
int mainFileVersion;
int appVersionCode = packInfo.versionCode;
if ( null != pi.metaData ) {
mainFileVersion = pi.metaData.getInt("mainVersion", appVersionCode);
patchFileVersion = pi.metaData.getInt("patchVersion", appVersionCode);
} else {
mainFileVersion = patchFileVersion = appVersionCode;
}
try {
mAPKExtensionFile = APKExpansionSupport.getAPKExpansionZipFile(ctx, mainFileVersion, patchFileVersion);
return true;
} catch (IOException e) {
e.printStackTrace();
}
}
return false;
}
@Override
public AssetFileDescriptor openAssetFile(Uri uri, String mode)
throws FileNotFoundException {
initIfNecessary();
String path = uri.getEncodedPath();
if ( path.startsWith("/") ) {
path = path.substring(1);
}
return mAPKExtensionFile.getAssetFileDescriptor(path);
}
I am not sure about this line of code in the above: ProviderInfo pi = pm.resolveContentProvider(getAuthority(), PackageManager.GET_META_DATA);
Is this correct?
From Android reference for PackageManager.resolveContentProvider().
public abstract ProviderInfo resolveContentProvider (String name, int flags)
Since: API Level 1
Find a single content provider by its base path name.
Parameters
name: The name of the provider to find.
flags: Additional option flags. Currently should always be 0.
Can someone confirm if i am doing something wrong or is it a bug.
Edit: everything works as expected when I upload my app for the first time - its only when I update the apk resulting in different version codes that this problem occurs.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…