2014-10-08 23 views
0

的AndroidManifest.xml: <provider android:authorities="com.mygame.expansion" android:exported="false" android:multiprocess="true" android:name="org.apache.cordova.xapkreader.XAPKProvider" />Java/Android:如何訪問AndroidManifest.xml中聲明的ContentProvider?

我有一個APEZProvider類,它來自於Android的SDK/extras文件夾中。它延伸ContentProvider

我也有XAPKProvider類,它擴展APEZProvider

public class XAPKProvider extends APEZProvider { 
@Override public String getAuthority() {return "com.mygame.expansion";} 

public int mainFileVersion = 0; 
public int patchFileVersion = 0; 

@Override public boolean initIfNecessary() { 
    if (mInit) return true; 
    Context ctx = getContext(); 
    try { 
    mAPKExtensionFile = APKExpansionSupport.getAPKExpansionZipFile (ctx, mainFileVersion, patchFileVersion); 
    mInit = true; 
    return true; 
    } catch (IOException e) { 
    e.printStackTrace(); 
    } 
    return false; 
} 
} 

我怎麼能訪問在AndroidManifest.xml文件中創建ContentProvider對象,這樣我可以修改mainFileVersionpatchFileVersion變量?

+0

你怎麼能訪問?你什麼意思? – pskink 2014-10-08 08:06:05

+0

我想能夠從另一個類中修改這些變量。 – Agamemnus 2014-10-08 08:21:35

回答

0

我發現另一個StackOverflow post讓我回答。我需要重寫「呼叫」。例如:

ContentResolver cr = cordova.getActivity().getApplicationContext().getContentResolver(); 
String expansionAuthority = bundle.getString("expansion_authority", ""); 
cr.call (Uri.parse("content://" + expansionAuthority), "set_expansion_file_versions", null, bundle); 

然後:..

@Override public Bundle call (String method, String arg, Bundle bundle) { 
if (method.equals("set_expansion_file_versions")) { 
    mainFileVersion = bundle.getInt("main_version" , 1); 
    patchFileVersion = bundle.getInt("patch_version", 1); 
    expansionAuthority = bundle.getString("expansion_authority", "com.sample.expansion"); 
    xmlDataReceived = true; 
    return null; 
} 
return null; 
}