Giter Site home page Giter Site logo

react-native-silent-update's Introduction

APK 拥有Root权限的 静默更新 react-native-silent-update

开始使用

$ npm install react-native-silent-update --save

链接原生库

$ react-native link react-native-silent-update

MainApplicationonCreate方法里面增加如下代码

   SilentUpdateManager.getInstance().setUpdateCallback(new UpdateCallBack() {
      @Override
      public void onUpdateAPKCallback(String uri) {
        Log.d(TAG, "App onUpdateAPKCallbackUri: " +uri);

        SilentUpdateUtil.getInstance().downloadAndInstallThroughCache(getApplicationContext(), uri);
      }
    });

    SilentUpdateUtil.getInstance().setSilentUpdateListener(new SilentUpdateListener() {
      @Override
      public void onUpdateSuccess() {
        Log.d("Tag", "App onUpdateSuccess: ");
        Intent intent2 = new Intent(getApplicationContext(), MainActivity.class);
        intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent2);
      }
      @Override
      public void onUpdateFail() {
        Log.d("TAG", "App onUpdateFail: ");
      }
    });

手动安装

Android

  1. Open up android/app/src/main/java/[...]/MainActivity.java
  • Add import com.reactlibrary.RNSilentUpdatePackage; to the imports at the top of the file
  • Add new RNSilentUpdatePackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-silent-update'
    project(':react-native-silent-update').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-silent-update/android')
    
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      compile project(':react-native-silent-update')
    

使用方法

import RNSilentUpdate from 'react-native-silent-update';

// TODO: What to do with the module?
RNSilentUpdate.updateAPK('https://raw.githubusercontent.com/Marcello168/TestAPK/master/app-release.apk')

react-native-silent-update's People

Contributors

marcello168 avatar

Stargazers

 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.