|
1 |
| -android-pluginmgr<br> |
2 |
| -dynamic load uninstalled apk<br> |
3 |
| -动态加载未安装APK<br> |
4 |
| -============================================================================================ |
5 |
| -<font color="red">Change: experiment分支开始支持so</font><br> |
| 1 | +## Android PluginManager ## |
| 2 | +**dynamic load uninstalled apk** |
| 3 | +### Introduction ### |
| 4 | + PluginManager is used to manage android applications like eclipse plugins. |
| 5 | +you can start an activity from an uninstalled apk placed in sdcard,just like it has installed or regist in the application's `AndroidManifest.xml`. |
| 6 | +### Support Features |
| 7 | +- a **normal** apk is regard as *plug-in* |
| 8 | +- start activity from plugin |
| 9 | +- start other activiy from plug activity |
| 10 | +- plug activity with **theme** |
| 11 | +- plug with custom `Application` |
| 12 | +- plug with **.so** |
| 13 | +- support android2.x |
6 | 14 |
|
7 |
| -此框架使动态加载APK非常简单<br> |
8 |
| -只需要2分钟,您就可以学会它的用法:<br> |
| 15 | + it's easy to use: |
| 16 | +### Steps: |
9 | 17 |
|
10 |
| -你可以直接下载demo工程--PlugLoadDemo 再对照阅读下文 |
| 18 | +- declare permission in your `AndroidManifest.xml`: |
11 | 19 |
|
12 |
| -首先,添加jar包: <br> |
13 |
| - pluginmgr-xx.jar (可以下载源码,自己用maven build)<br> |
14 |
| - dexmaker-xx.jar (此时最新版为dexmaker-1.1.jar)<br> |
15 |
| - 到您的app的libs目录<br> |
16 |
| - |
17 |
| -然后,在您App的 AndroidManifest.xml 文件中做两件事:<br> |
18 |
| -1、添加读写SD卡的权限: |
19 |
| - |
20 |
| - <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" /> |
21 |
| - <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> |
22 |
| - |
23 |
| -2、注册一个Activity |
24 |
| - |
25 |
| - <activity android:name="androidx.pluginmgr.PluginActivity" /> <br> |
26 |
| - |
27 |
| -要想启动一个未安装的APK其中的Activity,您只需要掌握一个类,两个方法即可!<br> |
28 |
| -这个类就是androidx.pluginmgr.PluginManager <br> |
29 |
| -看代码:<br> |
30 |
| -第一步, 加载插件 <br> |
31 |
| - PluginManager mgr = PluginManager.getInstance(Context);//传入您的context对象 <br> |
32 |
| - // 第1个方法 <br> |
33 |
| - mgr.loadPlugin(new File(您的插件路径));//加载,路径可以是单独一个apk,或者一个包含多个apk的目录 <br> |
34 |
| -第二步,启动插件Activity <br> |
35 |
| - // 第2个方法 <br> |
36 |
| - mgr.startActivity(context, new Intent().setComponentName(插件包名, Activity全类名))); <br> |
37 |
| - 如果你只是想启动MainActivity, 只须: mgr.startMainActivity(context, 插件包名); <br> |
38 |
| - |
39 |
| - 被加载的插件apk无须引入任何额外的依赖,也可以独立运行 <br> |
40 |
| - 怎么样,是不是很简单呢? <br> |
41 |
| - <br> |
42 |
| - ------------------------------------------------------------- |
43 |
| - <br> |
44 |
| - 如果您感兴趣深入了解,请看下文,否则请return:<br> |
45 |
| - <br> |
46 |
| - 额外功能:<br> |
47 |
| - <br> |
48 |
| - 一个插件还可以启动另一个插件里的Activity,或宿主的Activity<br> |
49 |
| - 插件可以使用宿主里的类,比如好几个插件都想调用宿主里的某个工具包里的类<br> |
50 |
| - ,那么可以把这个包抽出成jar包,供插件依赖使用,插件如果不需要独立安装运行的话,<br> |
51 |
| - 可以将这个jar包不要放在Android project 的 libs目录,而是change another directory,such as ‘mylib’<br> |
52 |
| - <br> |
53 |
| - 限制<br> |
54 |
| - 1、插件apk里不要假定包名就是清单文件声明的包名,因为包名会在被加载后变成和宿主一样的包名<br> |
55 |
| - 2、暂不支持插件的service, 未来将支持切换时间运行的service<br> |
56 |
| - 3、不支持 activity 的 launch mode<br> |
57 |
| - |
58 |
| -关于作者:<br> |
59 |
| - email: 1084940623@qq.com <br> |
60 |
| - blog: http://blog.csdn.net/hkxxx <br> |
61 |
| - |
62 |
| -许可<br> |
| 20 | + `<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />` |
| 21 | + `<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />` |
63 | 22 |
|
64 |
| -**本项目采用 Apache Licence 2.0 授权协议:<br> |
65 |
| -Apache Licence是著名的非盈利开源组织Apache采用的协议。该协议和BSD类似,同样鼓励代码共享和尊重原作者的著作权,同样允许代码修改<br>,再发布(作为开源或商业软件)<a href="http://www.oschina.net/question/12_2828">更多...</a><br> |
66 |
| -Copyright (c) 2014, KJFrameForAndroid Open Source Project, Zhang Tao.<br> |
| 23 | +- regist an activity |
67 | 24 |
|
68 |
| -Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the<br> License. You may obtain a copy of the License at<br> |
| 25 | + `<activity android:name="androidx.pluginmgr.PluginActivity" />` |
69 | 26 |
|
70 |
| - http://www.apache.org/licenses/LICENSE-2.0<br> |
71 |
| -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS<br> IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific<br> language governing permissions and limitations under the License.<br> |
| 27 | +- load plugin from plug apk: |
| 28 | + ```java |
| 29 | + PluginManager pluginMgr = PluginManager.getInstance(MyActivity); |
| 30 | + File myPlug = new File("/mnt/sdcard/Download/myplug.apk"); |
| 31 | + PlugInfo plug = pluginMgr.loadPlugin(myPlug).iterator().next(); |
| 32 | + ``` |
| 33 | +- start activity: |
| 34 | + ```java |
| 35 | + pluginMgr.startMainActivity(context, Plug.getPackageName()); |
| 36 | + ``` |
| 37 | +### Copywrite ### |
| 38 | +```java |
| 39 | +/** |
| 40 | + * Copyright (C) 2015 HouKx <hkx.aidream@gmail.com> |
| 41 | + * |
| 42 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 43 | + * you may not use this file except in compliance with the License. |
| 44 | + * You may obtain a copy of the License at |
| 45 | + * |
| 46 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 47 | + * |
| 48 | + * Unless required by applicable law or agreed to in writing, software |
| 49 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 50 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 51 | + * See the License for the specific language governing permissions and |
| 52 | + * limitations under the License. |
| 53 | + **/ |
| 54 | +``` |
0 commit comments