Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
keyongyu committed Sep 4, 2017
1 parent f9a6f1a commit 776aab9
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 9 deletions.
34 changes: 25 additions & 9 deletions project/TestPlugin/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,36 @@
package="com.example.TestPlugin"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="22"/>
<application android:name="com.morgoo.droidplugin.PluginApplication" android:label="@string/app_name"
android:icon="@drawable/ic_launcher" android:theme="@style/AppTheme">

<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="22"/>
<application
android:name="com.morgoo.droidplugin.PluginApplication"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name="MyActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="orientation"
>
android:name="MyActivity"
android:configChanges="orientation"
android:label="@string/app_name"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:configChanges="orientation"
android:label="Test"
android:screenOrientation="portrait"
android:enabled="false">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

</application>
</manifest>
85 changes: 85 additions & 0 deletions project/TestPlugin/src/com/example/TestPlugin/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.example.TestPlugin;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.RemoteException;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import com.morgoo.droidplugin.pm.PluginManager;
import com.morgoo.helper.Log;

import java.io.File;

import static com.morgoo.helper.compat.PackageManagerCompat.INSTALL_FAILED_NOT_SUPPORT_ABI;
import static com.morgoo.helper.compat.PackageManagerCompat.INSTALL_SUCCEEDED;

public class MainActivity extends AppCompatActivity {
private Handler mHandler = new Handler();

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

new Thread() {
@Override
public void run() {
doInstall(new File(Environment.getExternalStorageDirectory(), "app.apk"));
}
}.start();
}

public Activity getActivity() {
return this;
}

private void doInstall(final File apkPath) {
try {
final PackageInfo info = getPackageManager().getPackageArchiveInfo(apkPath.getAbsolutePath(), PackageManager.GET_ACTIVITIES);
if (info == null) {
mHandler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(getActivity(), "apk损坏\n" + apkPath.getAbsolutePath(), Toast.LENGTH_SHORT).show();
}
});
return;
}
final int re = PluginManager.getInstance().installPackage(apkPath.getAbsolutePath(), 0);
mHandler.post(new Runnable() {
@Override
public void run() {
switch (re) {
case PluginManager.INSTALL_FAILED_NO_REQUESTEDPERMISSION:
Toast.makeText(getActivity(), "安装失败,文件请求的权限太多", Toast.LENGTH_SHORT).show();
break;
case INSTALL_FAILED_NOT_SUPPORT_ABI:
Toast.makeText(getActivity(), "宿主不支持插件的abi环境,可能宿主运行时为64位,但插件只支持32位", Toast.LENGTH_SHORT).show();
break;
case INSTALL_SUCCEEDED:
Toast.makeText(getActivity(), "安装完成", Toast.LENGTH_SHORT).show();
PackageManager pm = getActivity().getPackageManager();
Intent intent = pm.getLaunchIntentForPackage(info.packageName);
if (intent != null) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Log.i("DroidPlugin", "start " + info.packageName + "@" + intent);
startActivity(intent);
} else {
Log.e("DroidPlugin", "pm " + pm.toString() + " no find intent " + info.packageName);
}
break;
}

}
});
} catch (RemoteException e) {
e.printStackTrace();
}
}
}

0 comments on commit 776aab9

Please sign in to comment.