Skip to content

Commit 557463d

Browse files
committed
update Demo
Signed-off-by: limpoxe <405977146@163.com>
1 parent 1f75ac8 commit 557463d

File tree

2 files changed

+25
-33
lines changed

2 files changed

+25
-33
lines changed

PluginMain/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
android:targetSdkVersion="21" />
1010

1111
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
12+
<uses-permission android:name="android.permission.INTERNET"/>
1213

1314
<application
1415
android:name="com.plugin.core.PluginApplication"

PluginMain/src/com/example/pluginmain/PluginListActivity.java

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class PluginListActivity extends Activity {
2929
private ViewGroup mList;
3030
private Button install;
3131
boolean isInstalled = false;
32-
32+
3333
@Override
3434
protected void onCreate(Bundle savedInstanceState) {
3535
super.onCreate(savedInstanceState);
@@ -38,12 +38,12 @@ protected void onCreate(Bundle savedInstanceState) {
3838
// 这行代码应当在Application的onCreate中执行。
3939
PluginLoader.initLoader(getApplication());
4040

41-
//监听插件安装 安装新插件后刷新当前页面
41+
// 监听插件安装 安装新插件后刷新当前页面
4242
registerReceiver(pluginChange, new IntentFilter(PluginLoader.ACTION_PLUGIN_CHANGED));
4343

4444
initView();
4545
}
46-
46+
4747
private void initView() {
4848
install = (Button) findViewById(R.id.install);
4949
install.setOnClickListener(new View.OnClickListener() {
@@ -52,41 +52,32 @@ private void initView() {
5252
public void onClick(View v) {
5353
if (!isInstalled) {
5454
isInstalled = true;
55-
Toast.makeText(PluginListActivity.this, "开始安装", Toast.LENGTH_LONG).show();
56-
try {
57-
InputStream assestInput = getAssets().open("PluginTest-debug.apk");
58-
String sdcardDest = Environment.getExternalStorageDirectory().getAbsolutePath()
59-
+ "/PluginTest-debug.apk";
60-
if (FileUtil.copyFile(assestInput, sdcardDest)) {
61-
PluginLoader.installPlugin(sdcardDest);
62-
}
63-
} catch (IOException e) {
64-
e.printStackTrace();
65-
Toast.makeText(PluginListActivity.this, "安装失败", Toast.LENGTH_LONG).show();
66-
}
67-
68-
try {
69-
InputStream assestInput = getAssets().open("HelloWork.apk");
70-
String sdcardDest = Environment.getExternalStorageDirectory().getAbsolutePath()
71-
+ "/HelloWork.apk";
72-
if (FileUtil.copyFile(assestInput, sdcardDest)) {
73-
PluginLoader.installPlugin(sdcardDest);
74-
}
75-
} catch (IOException e) {
76-
e.printStackTrace();
77-
Toast.makeText(PluginListActivity.this, "安装失败", Toast.LENGTH_LONG).show();
78-
}
79-
80-
81-
55+
56+
copyAndInstall("PluginTest-debug.apk");
57+
copyAndInstall("HelloWork.apk");
58+
// copyAndInstall("Game1-debug.apk");
59+
8260
}
8361
}
8462
});
8563

8664
mList = (ViewGroup) findViewById(R.id.list);
8765
listAll(mList);
8866
}
89-
67+
68+
private void copyAndInstall(String name) {
69+
try {
70+
InputStream assestInput = getAssets().open(name);
71+
String sdcardDest = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + name;
72+
if (FileUtil.copyFile(assestInput, sdcardDest)) {
73+
PluginLoader.installPlugin(sdcardDest);
74+
}
75+
} catch (IOException e) {
76+
e.printStackTrace();
77+
Toast.makeText(PluginListActivity.this, "安装失败", Toast.LENGTH_LONG).show();
78+
}
79+
}
80+
9081
private void listAll(ViewGroup root) {
9182
root.removeAllViews();
9283

@@ -107,15 +98,15 @@ public void onClick(View v) {
10798
startActivity(intent);
10899
}
109100
});
110-
101+
111102
LayoutParams layoutParam = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
112103
layoutParam.topMargin = 10;
113104
layoutParam.bottomMargin = 10;
114105
layoutParam.gravity = Gravity.LEFT;
115106
root.addView(button, layoutParam);
116107
}
117108
}
118-
109+
119110
private final BroadcastReceiver pluginChange = new BroadcastReceiver() {
120111
@Override
121112
public void onReceive(Context context, Intent intent) {

0 commit comments

Comments
 (0)