문제

For work I maintain an internal 'market' where new app releases can be uploaded and downloaded. I also maintain a launcher that can select from our many apps and launch them (some are the same app 'branded' differently). I can currently populate this list with the package name and the version code, but I would also like to add in the SVN branch.

I was thinking about having a script that would add the branch info as XML either to the manifest as a custom attribute or as a separate XML file. Ideally, this could be accessible publicly by the PackageManager. Is this possible?

Alternatively, can I programmatically change the APK name? Then I could use "$name - $branch" as the new name.

도움이 되었습니까?

해결책

I was thinking about having a script that would add the branch info as XML either to the manifest as a custom attribute or as a separate XML file. Ideally, this could be accessible publicly by the PackageManager. Is this possible?

You have add a <meta-data> element to a component's element (e.g., <activity>) and access the metadata XML content via PackageManager:

    <receiver android:name="com.commonsware.cwac.wakeful.AlarmReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
        </intent-filter>

        <meta-data
            android:name="com.commonsware.cwac.wakeful"
            android:resource="@xml/wakeful"/>
    </receiver>

The component would access the metadata through code like this:

PackageManager pm=ctxt.getPackageManager();
ComponentName cn=new ComponentName(ctxt, getClass());
ActivityInfo ai=pm.getReceiverInfo(cn, PackageManager.GET_META_DATA);
XmlResourceParser xpp=ai.loadXmlMetaData(pm, "com.commonsware.cwac.wakeful");

Your custom build process could then adjust the XML resource pointed to by <meta-data> to contain whatever you want.

Alternatively, can I programmatically change the APK name?

You can name the APK file whatever you want on your hard drive, but I would not count on that name remaining intact through the installation process.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top