Coder Social home page Coder Social logo

silentupdate's Introduction

SilentUpdate

静默更新,socket运用 服务端与客户端

.jks是系统签名文件,这个需要根据自己的系统来进行签名,需要修改

[SC60][Android7.1][Document]各版本静默安装应用

Android 不同实现静默安装实现方法

Android7

/** * *

  • @param context
  • @param filePath */ public void installSilentWithReflection(String filePath, String packName) { try { PackageManager packageManager = mContext.getPackageManager(); Method method = packageManager.getClass().getDeclaredMethod("installPackage", new Class[]{Uri.class, IPackageInstallObserver.class, int.class, String.class}); method.setAccessible(true); File apkFile = new File(filePath); Uri apkUri = Uri.fromFile(apkFile); method.invoke(packageManager, new Object[]{apkUri, new PackInstallObserver(), Integer.valueOf(2), packName}); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }

/** * */ static class PackInstallObserver extends IPackageInstallObserver.Stub { @Override public void packageInstalled(String packageName, int returnCode) throws RemoteException { //returnCode } }

Android 9

/**

  • @param filepathApk */ @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public void installPackage(String filepathApk) { File file=new File(filepathApk); String apkName=filepathApk.substring(filepathApk.lastIndexOf(File.separator)+1,filepathApk.lastIndexOf(". apk")); //PackageInstaller PackageInstaller packageInstaller = mContext.getPackageManager() .getPackageInstaller(); PackageInstaller.SessionParams params=new PackageInstaller .SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL); PackageInstaller.Session session=null; OutputStream outputStream=null; FileInputStream inputStream=null; try { //Session int sessionId = packageInstaller.createSession(params); //Session session=packageInstaller.openSession(sessionId); //apksession outputStream = session.openWrite(apkName, 0, -1); inputStream=new FileInputStream(file); byte[] buffer=new byte[4096]; int n; //apksession while ((n=inputStream.read(buffer))>0){ outputStream.write(buffer,0,n); } //“files still open” inputStream.close(); inputStream=null; outputStream.flush(); outputStream.close(); outputStream=null; //intentactivity Intent intent=new Intent(); PendingIntent pendingIntent=PendingIntent.getActivity(mContext,0,intent,0); IntentSender intentSender = pendingIntent.getIntentSender(); // session.commit(intentSender); } catch (IOException e) { throw new RuntimeException("Couldn't install package", e); } catch (RuntimeException e) {

if (session != null) { session.abandon(); } throw e; }finally { } } // packageInstaller.registerSessionCallback(new PackageInstaller.SessionCallback() { @Override public void onCreated(int sessionId) { } @Override public void onBadgingChanged(int sessionId) { } @Override public void onActiveChanged(int sessionId, boolean active) { } @Override public void onProgressChanged(int sessionId, float progress) { } @Override public void onFinished(int sessionId, boolean success) { } 静默安装需要获取系统权限android.permission.INSTALL_PACKAGES,并且AndroidManifest.xml配置 android:sharedUserId="android.uid.system",使用 系统签名打包

silentupdate's People

Contributors

andysung avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.