Using the PackageManager, you can request / etc actions on the system in all installed packages (APKs). Sample ApiDemos code in the Android SDK uses this in the class com.example.android.apis.ApiDemos .
Code example:
void findAddOnActivities() { Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory("myPackage.intent.category.ADDON"); PackageManager pm = getPackageManager(); List<ResolveInfo> list = pm.queryIntentActivities(mainIntent, 0);
Fragment Manifest:
<activity android:label="My external Add-on" android:name=".addons.TestAddon" > <intent-filter > <action android:name="android.intent.action.MAIN" /> <category android:name="myPackage.intent.category.ADDON" /> </intent-filter> </activity>
To access the database and control access / security modification: Declare your own permissions in the manifest:
<permission android:name="com.mycompany.myapp.database.permission.READ" android:label="@string/read_permission" android:protectionLevel="signatureOrSystem"></permission> <permission android:name="com.mycompany.myapp.database.permission.WRITE" android:label="@string/write_permission" android:protectionLevel="signatureOrSystem"></permission>
The protectionLevel tag will ensure that only this can be provided only by APKs that are part of the image or signed with the same key as the main application.
There are many ways an addon can access your database. The remote service or interface will work. This happens in my application, my main application has a DBManager class that already does a bunch of read / write to the database. Therefore, I just use this class in my external application, and it can do all the reads / writes since the packages are signed with the same key.
If you do not want to use the same key to sign packages, consider using a remote service, for example, in the RemoteService.java code example. Check out the Android Developers Guide for more details. I am not an expert on Android services, so any feedback from others is likely to be helpful.
source share