android 静默暗转_android系统设置添加静默安装接口

基于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;

}

}

};

+}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值