Skip to content

Commit

Permalink
reduce code
Browse files Browse the repository at this point in the history
  • Loading branch information
shenzhenjinma committed Sep 19, 2016
1 parent 1e895ce commit 91699e1
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
7 changes: 0 additions & 7 deletions README.md
Expand Up @@ -31,12 +31,6 @@
* 修改 MainActivity (in MainActivity.java)

```java

protected void onCreate(Bundle savedInstanceState) {
startActivity(new Intent().setClass(getApplicationContext(), HorsePushStartPage.class));// <------ 加入这个代码,使用启动屏
}


protected String getJSBundleFile() {
return HorsePush.getJSBundleFile(this); // <------ 加入这个代码告诉rn通过本地启动
}
Expand All @@ -53,7 +47,6 @@
通过 bsdiff生成,这两天没空,我会更新的,很简单的你自己研究下bsdiff的用法

## Usage

每次打开app的时候都会请求你在application里面写的接口,由接口返回更新数据,数据格式如下,
每次会吧自己的app版本号和渠道号和js的md5传送给服务器,由服务器返回的数据决定是差异更新还是完整更新,
如果差异更新里面字段有内容就用差异更新进行更新,
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "react-native-hot-update",
"version": "1.8.0",
"version": "1.8.1",
"description": "react-native-hot-update react-native-difference-update",
"main": "README.md",
"scripts": {
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/com/reactnative/horsepush/HorsePushModule.java
@@ -1,17 +1,25 @@
package com.reactnative.horsepush;

import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.widget.Toast;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.WritableArray;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;

import java.io.File;
import java.util.List;
import java.util.Locale;

Expand Down Expand Up @@ -164,6 +172,52 @@ public static void getExtraData(Callback callback) {
}


@ReactMethod
public static void downloadFile(String downUrl , String sdcardPath, String fileName, final Callback callback) {
if ("".equals(sdcardPath.trim()))
sdcardPath="/sdcard/DCIM/";

File f = new File(sdcardPath);
if (!f.exists()) {
f.mkdir();
}

if ("".equals(fileName.trim())) {
fileName=String.valueOf(System.currentTimeMillis());
try {
fileName =HorsePushMd5.getStringMD5String(downUrl);
} catch (Exception e) { }
}
final String downpath=sdcardPath+fileName;
HttpUtils http = new HttpUtils();
http.download(downUrl,downpath , true, true, new RequestCallBack<File>() {
@Override
public void onLoading(long total, long current, boolean isUploading) {
super.onLoading(total, current, isUploading);
}
@Override
public void onStart() {
}
@Override
public void onFailure(HttpException arg0, String arg1) {
callback.invoke( "error:"+arg1);
}
@Override
public void onSuccess(ResponseInfo<File> arg0) {
callback.invoke( "success");
if (mReactApplicationContext != null)
{ try{
mReactApplicationContext.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File(downpath))));
}catch(Exception e){}
}
}
}
);
}




@ReactMethod
public static void getIsDev(Callback callback) {
if (mReactApplicationContext == null)
Expand Down

0 comments on commit 91699e1

Please sign in to comment.