基于android6.0 设置代码添加静默安装接口
--- a/packages/apps/Settings/AndroidManifest.xml
+++ b/packages/apps/Settings/AndroidManifest.xml
@@ -1846,6 +1846,11 @@
+
+
+
android:name=".bluetooth.DockEventReceiver">
--- /dev/null
+++ b/packages/apps/Settings/src/com/android/settings/yfslientinstall.java
@@ -0,0 +1,93 @@
+package com.android.settings;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+import android.widget.Toast;
+import android.os.Handler;
+import android.os.Message;
+import java.io.;
+import java.text.;
+import java.util.*;
+import android.content.pm.IPackageInstallObserver;
+import android.content.pm.IPackageManager;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageInstaller;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.net.Uri;
+public class yfslientinstall extends BroadcastReceiver
+{
static final String ACTION = "com.android.yf_slient_install";
Context mcontext;
String TAG = "yfslientinstall";
String mpkgname = "";
boolean isboot;
+@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(ACTION)) {
mcontext = context;
String apkpath = intent.getStringExtra("path");
isboot = intent.getBooleanExtra("isboot", true);
Log.i(TAG, "===apkpath:"+apkpath + " isboot:"+isboot);
startbginstall(apkpath, isboot);
}
}
private void startbginstall(String apkpath, boolean bootafterinstall){
Uri mPackageURI;
if(apkpath != null){
PackageManager pm = mcontext.getPackageManager();
PackageInstallObserver observer = new PackageInstallObserver();
File apkFile = new File(apkpath);
if(apkFile.exists()){
mPackageURI = Uri.fromFile(apkFile);
pm.installPackage(mPackageURI, observer, 2, null);
}else{
Log.e(TAG, "===apk file is not exists!");
}
}
}
class PackageInstallObserver extends IPackageInstallObserver.Stub {
public void packageInstalled(String packageName, int returnCode) {
mpkgname = packageName;
Message msg = mHandler.obtainMessage(1);
msg.arg1 = returnCode;
mHandler.sendMessage(msg);
}
}
private Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
if(msg.arg1 == PackageManager.INSTALL_SUCCEEDED){
Log.i(TAG, "===apk install successed!");
if(isboot){
try{
Intent startintent = mcontext.getPackageManager().getLaunchIntentForPackage(mpkgname);
startintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mcontext.startActivity(startintent);
}catch(Exception e){
Log.i(TAG, "===pakcagename:"+mpkgname+"start failed");
}
}
}else{
Log.e(TAG, "===apk install failed, apk is invalid!");
}
break;
default:
break;
}
}
};
+}