=======
作用是静默安装app,然后跳转,不会弹系统的安装对话框,实际apk安装在data/data/xxx/Plugin文件夹下面,使用adb uninstall卸载不了
demo下载地址(包含module):
https://download.csdn.net/download/u010672559/10549320
===========
1.引入module
2.配置application,并注册
3.配置DroidPlugin的清单文件,修改com.morgoo.droidplugin_stub_P00~P08为自己的包名com.example.droidplugin_stub_P08,修改PluginManager.STUB_AUTHORITY_NAME为自己的名称com.example.droidplugin_stub,不改这些在安装的时候会提示provider冲突
4.安装,删除apk的api,安装后apk文件在data/data/xxx/Plugin文件夹下面,使用adb uninstall卸载不了
int result= PluginManager.getInstance().installPackage(path,0);//耗时操作,需在工作线程执行,返回1是安装成功
PluginManager.getInstance().deletePackage("com.mgtv.operator",0);
5.跳转时需要安装的apk的界面有action配置,并能跳转,然后通过设置action跳转,也可通过包名类名跳转
6.其他
boolean connect = PluginManager.getInstance().isConnected();
在主activity-oncreate时开始时还是false,要等一会时才会是true
boolean isRequestPermission = (result == PluginManager.INSTALL_FAILED_NO_REQUESTEDPERMISSION);
==========
<application
android:name=".MyApp"
import android.app.Application;
import android.content.Context;
import android.nfc.Tag;
import android.util.Log;
import com.morgoo.droidplugin.PluginHelper;
public class MyApp extends Application {
public static final String TAG = "xiaozheng";
@Override
public void onCreate() {
super.onCreate();
// 这里必须在super.onCreate方法之后,顺序不能变
Log.d(TAG, "onCreate()");
PluginHelper.getInstance().applicationOnCreate(getBaseContext());
}
@Override
protected void attachBaseContext(Context base) {
PluginHelper.getInstance().applicationAttachBaseContext(base);
super.attachBaseContext(base);
Log.d(TAG, "attachBaseContext");
}
}
---------
<provider
android:name=".stub.ContentProviderStub$StubP08"
android:authorities="com.example.droidplugin_stub_P08"
android:exported="false"
android:label="@string/stub_name_povider"
android:process=":PluginP08" />
----------
public static final String STUB_AUTHORITY_NAME = "com.example.droidplugin_stub";
-------
final String path = "/storage/emulated/0/test1.apk";
new Thread(new Runnable() {
@Override
public void run() {
try {
int result= PluginManager.getInstance().installPackage(path,0);
Log.d(TAG, "result = "+result);
if(result ==1){
gotoPlugin("跳转的actionname或使用包名类名跳转","data");
}
}catch (Exception e){
e.printStackTrace();
}
}
}).start();
// 跳转控件
private void gotoPlugin(String packageName,String data) {
Log.d(TAG, "gotoPlugin packageName="+packageName+"data="+data);
Intent intent = new Intent();
intent.setAction(packageName);
startActivity(intent);
}
---------