问题
I have implemented plugin system in my applications. Plugins exist as the standalone applications.
What is the best way to access drawables from plugins in main application ?
回答1:
You have few options:
ContentProvider - not definitely need to be based over
SQLite
database.manifest attribute
android:sharedUserId
From docs:
The name of a Linux user ID that will be shared with other applications. By default, Android assigns each application its own unique user ID. However, if this attribute is set to the same value for two or more applications, they will all share the same ID — provided that they are also signed by the same certificate. Application with the same user ID can access each other's data and, if desired, run in the same process.
See http://developer.android.com/guide/topics/manifest/manifest-element.html#uid
PackageManager.getResourcesForApplication() to retrieve the resources associated with an application.
Usage:
PackageManager pm = getPackageManager(); try { Resources resources = pm.getResourcesForApplication("com.example.app"); int id = resources.getIdentifier("ic_launcher", "drawable", "com.example.app"); Drawable d = resources.getDrawable(id) } catch (NameNotFoundException e) { e.printStackTrace(); }
回答2:
I think ContentProvider is your best choice. They were specifically designed to "share data between multiple applications". Here is a reference from developer.android: http://developer.android.com/reference/android/content/ContentProvider.html And here is a detailed guide: http://www.vogella.com/articles/AndroidSQLite/article.html
来源:https://stackoverflow.com/questions/11626359/share-drawables-between-applications