Browse Source

根据会议要求修改了相关交互函数:
1,所有参数以json的形式传入;
2,函数都要有返回,本身功能不需要返回的函数返回调用结果

lyn 5 years ago
parent
commit
4b375b9e05

+ 1 - 1
app/build.gradle

@@ -7,7 +7,7 @@ android {
         minSdkVersion 19
         targetSdkVersion 28
         versionCode 1
-        versionName "1.0"
+        versionName "1.0.1"
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
         ndk {
             //APP的build.gradle设置支持的SO库架构

+ 8 - 0
app/src/main/java/com/haochuan/hciptvbasic/Util/Logger.java

@@ -41,6 +41,14 @@ public class Logger {
         messageToJs(message);
     }
 
+    public static void e(@NonNull int code, @NonNull String message){
+        message = String.format("错误代码: %s,错误信息:%s",code,message);
+        if(BuildConfig.isDebug){
+            Log.e(TAG,message);
+        }
+        messageToJs(message);
+    }
+
 
     private static void messageToJs(@NonNull String message){
         //将日志传给MainActivity,然后传给js

+ 25 - 14
app/src/main/java/com/haochuan/hciptvbasic/Util/MacUtil.java

@@ -58,16 +58,22 @@ public final class MacUtil {
      */
     @SuppressLint("HardwareIds")
     private static String getLocalMacAddressFromWifiInfo(Context context) {
-        WifiManager wifi = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
-        WifiInfo info = null;
-        if (wifi != null) {
-            info = wifi.getConnectionInfo();
-        }
-        String mac = null;
-        if (info != null) {
-            mac = info.getMacAddress();
+        try{
+            WifiManager wifi = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
+            WifiInfo info = null;
+            if (wifi != null) {
+                info = wifi.getConnectionInfo();
+            }
+            String mac = null;
+            if (info != null) {
+                mac = info.getMacAddress();
+            }
+            return mac;
+        }catch (Exception e){
+            e.printStackTrace();
+            return "";
         }
-        return mac;
+
     }
 
     /**
@@ -75,13 +81,18 @@ public final class MacUtil {
      */
     private static String getMacAddress(Context context) {
         // 如果是6.0以下,直接通过wifimanager获取
-        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
-            String macAddress0 = getMacAddress0(context);
-            if (!TextUtils.isEmpty(macAddress0)) {
-                return macAddress0;
+        try{
+            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
+                String macAddress0 = getMacAddress0(context);
+                if (!TextUtils.isEmpty(macAddress0)) {
+                    return macAddress0;
+                }
             }
+            return getMacAddress2();
+        }catch (Exception e){
+            e.printStackTrace();
+            return "";
         }
-        return getMacAddress2();
     }
 
     private static String getMacAddress2() {

+ 9 - 0
app/src/main/java/com/haochuan/hciptvbasic/Util/MessageCode.java

@@ -0,0 +1,9 @@
+package com.haochuan.hciptvbasic.Util;
+
+public class MessageCode {
+    public final static int EXCEPTION_ERROR = -1;       //异常抛出
+    public final static int SUCCESS = 0;                //成功
+    public final static int PARAM_ERROR = 1;            //参数错误
+    public final static int PLAYER_OBJ_NULL = 2;        //播放器对象为空
+    public final static int PLAYER_NO_INIT = 3;        //播放器对象未初始化
+}

+ 3 - 3
app/src/main/java/com/haochuan/hciptvbasic/Util/ToolsUtil.java

@@ -79,15 +79,15 @@ public class ToolsUtil {
                     return getIntentJson;
                 }else{
                     Logger.d("getIntentJson, bundle is null");
-                    return "";
+                    return "{}";
                 }
             }else{
                 Logger.d("getIntentJson, intent is null");
-                return "";
+                return "{}";
             }
         }catch (Exception e){
             e.printStackTrace();
-            return "";
+            return "{}";
         }
     }
 

+ 3 - 3
app/src/main/java/com/haochuan/hciptvbasic/test/TestActivity.java

@@ -27,12 +27,12 @@ public class TestActivity extends BaseWebActivity {
             String y = "30";
             String width = "640";
             String height = "360";
-            getPlayerToJS().play(url,"20",x,y,width,height);
+            getPlayerToJS().play("");
         });
 
         Button changeBtn = findViewById(R.id.change_btn);
         changeBtn.setOnClickListener(v ->
-                getPlayerToJS().change("0","0","1280","720"));
+                getPlayerToJS().change(""));
 
         Button pauseBtn = findViewById(R.id.pause_btn);
         pauseBtn.setOnClickListener(v -> getPlayerToJS().pause());
@@ -61,7 +61,7 @@ public class TestActivity extends BaseWebActivity {
         });
 
         Button exitBtn = findViewById(R.id.exit_btn);
-        exitBtn.setOnClickListener(v -> getPlayerToJS().exit());
+        exitBtn.setOnClickListener(v -> getPlayerToJS().stop());
 
         //显示位置
         getLocations();

+ 5 - 0
app/src/main/java/com/haochuan/hciptvbasic/video/BaseMediaPlayer.java

@@ -88,4 +88,9 @@ public abstract class BaseMediaPlayer extends FrameLayout {
     public abstract int getCurrentPlayPosition();
 
 
+    /*
+     * 获得当前播放状态
+     * */
+    public abstract int getCurrentStatus();
+
 }

+ 28 - 3
app/src/main/java/com/haochuan/hciptvbasic/video/EmptyControlVideoView.java

@@ -16,7 +16,7 @@ import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;
 public class EmptyControlVideoView extends StandardGSYVideoPlayer {
 
     IVideoPlayer iVideoPlayerListener ;
-    private int startTime = 0;                                 //播放器开始的时间
+    private int startTime = 0;                                 //播放器开始的时间,单位毫秒
 
     public EmptyControlVideoView(Context context, Boolean fullFlag) {
         super(context, fullFlag);
@@ -76,7 +76,13 @@ public class EmptyControlVideoView extends StandardGSYVideoPlayer {
     public void onPrepared() {
         super.onPrepared();
         if(startTime > 0){
-            seekTo(startTime);
+            if(startTime >= getDuration()){
+                //如果开始时间大于或者等于视频总时长,则跳转到距离结束5秒的位置
+                seekTo(getDuration() -5000);
+            }else{
+                seekTo(startTime);
+            }
+
         }
     }
 
@@ -127,7 +133,26 @@ public class EmptyControlVideoView extends StandardGSYVideoPlayer {
     }
 
     public void setStartTime(int time){
-        this.startTime = time;
+        this.startTime = time * 1000;
+    }
+
+    public int getCurrentStatus(){
+        int currentStatus = 0;
+        switch (mCurrentState){
+            case 2:
+                currentStatus =1;
+                break;
+            case 5:
+                currentStatus =2;
+                break;
+            case 6:
+                currentStatus =3;
+                break;
+            default:
+                currentStatus =0;
+                break;
+        }
+        return currentStatus;
     }
 
     /*-----------------*/

+ 6 - 0
app/src/main/java/com/haochuan/hciptvbasic/video/HCGsyVideoPlayer.java

@@ -108,6 +108,12 @@ public class HCGsyVideoPlayer extends BaseMediaPlayer {
             return 0;
         }
     }
+
+    @Override
+    public int getCurrentStatus() {
+        return mEmptyControlVideo.getCurrentStatus();
+    }
+
     @Override
     public void release(){
         mEmptyControlVideo.release();

+ 5 - 0
app/src/main/java/com/haochuan/hciptvbasic/video/HCPlayer.java

@@ -163,6 +163,11 @@ public class HCPlayer extends BaseMediaPlayer implements IVideoPlayer{
         return mHcGsyVideoPlayer.getCurrentPlayPosition();
     }
 
+    @Override
+    public int getCurrentStatus() {
+        return 0;
+    }
+
     public void setSpeed(@NonNull float speed){
         mHcGsyVideoPlayer.setSpeed(speed);
     }

+ 156 - 56
app/src/main/java/com/haochuan/hciptvbasic/webview/PlayerToJS.java

@@ -5,6 +5,7 @@ import android.animation.ValueAnimator;
 import android.app.Activity;
 import android.content.Context;
 import android.content.Intent;
+import android.text.TextUtils;
 import android.view.ViewGroup;
 import android.view.animation.LinearInterpolator;
 import android.webkit.JavascriptInterface;
@@ -17,6 +18,14 @@ import com.haochuan.hciptvbasic.Util.MathUtil;
 import com.haochuan.hciptvbasic.Util.ScreenSnap;
 import com.haochuan.hciptvbasic.video.BaseMediaPlayer;
 
+import org.json.JSONObject;
+
+import static com.haochuan.hciptvbasic.Util.MessageCode.EXCEPTION_ERROR;
+import static com.haochuan.hciptvbasic.Util.MessageCode.PARAM_ERROR;
+import static com.haochuan.hciptvbasic.Util.MessageCode.PLAYER_NO_INIT;
+import static com.haochuan.hciptvbasic.Util.MessageCode.PLAYER_OBJ_NULL;
+import static com.haochuan.hciptvbasic.Util.MessageCode.SUCCESS;
+
 
 public class PlayerToJS {
     private Context context;                        //MainActivity 句柄
@@ -98,6 +107,7 @@ public class PlayerToJS {
 
     /*
     * 播放函数
+    *
      * @param x                  播放器x坐标
      * @param y                  播放器y坐标
      * @param width              播放器宽度
@@ -105,16 +115,45 @@ public class PlayerToJS {
      * @param seekTime           播放初始位置,单位 s
     * */
     @JavascriptInterface
-    public void play(String url,String seekTime, String x,String y,String width, String height){
-        videoPlay(url,seekTime,x,y,width,height);
+    public int play(String playParamJson){
+        Logger.d("调用play函数,参数:" + playParamJson);
+        try{
+            JSONObject playParam = new JSONObject(playParamJson);
+            String url = playParam.has("url")?playParam.get("url").toString():"";
+            if(TextUtils.isEmpty(url)){
+                Logger.e(PARAM_ERROR,"调用play函数,url为空,不能执行播放");
+                return PARAM_ERROR;
+            }
+            String seekTime = playParam.has("seekTime")?playParam.get("seekTime").toString():"0";
+            String x = playParam.has("x")?playParam.get("x").toString():"0";
+            String y = playParam.has("y")?playParam.get("y").toString():"0";
+            String width = playParam.has("width")?playParam.get("width").toString():"1280";
+            String height = playParam.has("height")?playParam.get("height").toString():"720";
+            return videoPlay(url,seekTime,x,y,width,height);
+        }catch (Exception e){
+            e.printStackTrace();
+            Logger.e(EXCEPTION_ERROR,"异常抛出:" + e.getMessage());
+            return EXCEPTION_ERROR;
+        }
     }
 
     /*
     * 改变播放器尺寸
+    * 参数定义同play函数
     * */
     @JavascriptInterface
-    public void change(String x,String y,String width, String height){
-        videoChange(x,y,width,height);
+    public int change(String changeParamJson){
+        try{
+            JSONObject changeParam = new JSONObject(changeParamJson);
+            String x = changeParam.has("x")?changeParam.get("x").toString():"0";
+            String y = changeParam.has("y")?changeParam.get("y").toString():"0";
+            String width = changeParam.has("width")?changeParam.get("width").toString():"1280";
+            String height = changeParam.has("height")?changeParam.get("height").toString():"720";
+            return videoChange(x,y,width,height);
+        }catch (Exception e){
+            e.printStackTrace();
+            return EXCEPTION_ERROR;
+        }
     }
 
 
@@ -122,36 +161,54 @@ public class PlayerToJS {
      * 暂停
      * */
     @JavascriptInterface
-    public void pause(){
+    public int pause(){
         if(baseMediaPlayer == null){
             Logger.e("播放器为空,不能暂停");
-            return;
+            return PLAYER_OBJ_NULL;
+        }
+        try{
+            baseMediaPlayer.pause();
+            return SUCCESS;
+        }catch (Exception e){
+            e.printStackTrace();
+            return EXCEPTION_ERROR;
         }
-        baseMediaPlayer.pause();
     }
 
     /*
      * 恢复
      * */
     @JavascriptInterface
-    public void resume(){
+    public int resume(){
         if(baseMediaPlayer == null){
             Logger.e("播放器为空,不能恢复");
-            return;
+            return PLAYER_OBJ_NULL;
+        }
+        try{
+            baseMediaPlayer.resume();
+            return SUCCESS;
+        }catch (Exception e){
+            e.printStackTrace();
+            return EXCEPTION_ERROR;
         }
-        baseMediaPlayer.resume();
     }
 
     /*
      * 快进到指定位置
      * */
     @JavascriptInterface
-    public void seek(int position){
+    public int seek(int position){
         if(baseMediaPlayer == null){
             Logger.e("播放器为空,不能拖动");
-            return;
+            return PLAYER_OBJ_NULL;
+        }
+        try{
+            baseMediaPlayer.seek(position);
+            return SUCCESS;
+        }catch (Exception e){
+            e.printStackTrace();
+            return EXCEPTION_ERROR;
         }
-        baseMediaPlayer.seek(position);
     }
 
 
@@ -159,25 +216,51 @@ public class PlayerToJS {
      * 资源释放
      * */
     @JavascriptInterface
-    public void release(){
+    public int release(){
         if(baseMediaPlayer == null){
             Logger.e("播放器为空,不能释放资源");
-            return;
+            return PLAYER_OBJ_NULL;
+        }
+        try{
+            baseMediaPlayer.release();
+            return SUCCESS;
+        }catch (Exception e){
+            e.printStackTrace();
+            return EXCEPTION_ERROR;
         }
-        baseMediaPlayer.release();
     }
 
     /*
     * 退出播放
     * */
     @JavascriptInterface
-    public void exit(){
+    public int stop(){
         if(baseMediaPlayer == null){
             Logger.e("播放器为空,不能退出");
-            return;
+            return PLAYER_OBJ_NULL;
+        }
+
+        try{
+            Activity activity = (Activity)context;
+            activity.runOnUiThread(this::destroyVideo);
+            return SUCCESS;
+        }catch (Exception e){
+            e.printStackTrace();
+            return EXCEPTION_ERROR;
+        }
+    }
+
+    /*
+    * 获取当前播放状态
+    * 状态说明:1,播放;2,暂停;3,播放完成停止;0,其他
+    * */
+    @JavascriptInterface
+    public int getPlayerStatus(){
+        if(baseMediaPlayer == null){
+            Logger.e("播放器为空,不能退出");
+            return PLAYER_OBJ_NULL;
         }
-        Activity activity = (Activity)context;
-        activity.runOnUiThread(this::destroyVideo);
+        return baseMediaPlayer.getCurrentStatus();
     }
 
     /**-------------------------------------------功能函数-----------------------------------------------*/
@@ -190,10 +273,10 @@ public class PlayerToJS {
     * @param height             播放器高度
     * @param seekTime           播放初始位置,单位 s
     * */
-    private void videoPlay(String url,String seekTime, String x,String y,String width, String height){
+    private int videoPlay(String url,String seekTime, String x,String y,String width, String height){
         if(baseMediaPlayer == null){
-            Logger.e("播放器为空,不能播放");
-            return;
+            Logger.e(PLAYER_OBJ_NULL,"播放器对象为空,不能播放");
+            return PLAYER_OBJ_NULL;
         }
         if(MathUtil.isDigitsOnly(x) && MathUtil.isDigitsOnly(y) && MathUtil.isDigitsOnly(width) && MathUtil.isDigitsOnly(height) && MathUtil.isDigitsOnly(seekTime)){
             int screenWidth = ScreenSnap.getScreenWidth(context);
@@ -211,7 +294,7 @@ public class PlayerToJS {
             }
             final int realSeekTime = transformSeekTime;
 
-            Logger.d(String.format("调用小窗口播放。转换坐标(%s, %s),宽高(%s, %s)", transformX, transformY, transformWidth, transformHeight));
+            Logger.d(String.format("调用播放函数。转换坐标(%s, %s),宽高(%s, %s)", transformX, transformY, transformWidth, transformHeight));
 
             Activity activity = (Activity)context;
             activity.runOnUiThread(()->{
@@ -220,9 +303,11 @@ public class PlayerToJS {
                 baseMediaPlayer.setStartTime(realSeekTime);
                 webView.requestFocus();
             });
+            return SUCCESS;
         }else{
-            Logger.w(String.format("请正确传递play函数参数:x:%s;y:%s;width:%s;height:%s;seekTime:%s",
+            Logger.e(PARAM_ERROR,String.format("请正确传递play函数参数:x:%s;y:%s;width:%s;height:%s;seekTime:%s",
                     x,y,width,height,seekTime));
+            return EXCEPTION_ERROR;
         }
     }
 
@@ -260,14 +345,15 @@ public class PlayerToJS {
      * @param width              待改变播放器宽度
      * @param height             待改变播放器高度
     * */
-    private void videoChange(String x,String y,String width, String height){
+    private int videoChange(String x,String y,String width, String height){
         if(baseMediaPlayer == null){
             Logger.w("baseMediaPlayer is null,不能调用play函数");
+            return PLAYER_OBJ_NULL;
         }
 
         if(baseMediaPlayer.getParent() == null){
             Logger.w("当前播放器没有启动,请先调用play函数启动");
-            return;
+            return PLAYER_NO_INIT;
         }
 
         if(MathUtil.isDigitsOnly(x) && MathUtil.isDigitsOnly(y) && MathUtil.isDigitsOnly(width) && MathUtil.isDigitsOnly(height)){
@@ -282,47 +368,61 @@ public class PlayerToJS {
             int fromY = (int)baseMediaPlayer.getY();
             int fromWidth = baseMediaPlayer.getWidth();
             int fromHeight = baseMediaPlayer.getHeight();
-            animChanged(fromX,toX,fromY,toY,fromWidth,toWidth,fromHeight,toHeight);
+            return animChanged(fromX,toX,fromY,toY,fromWidth,toWidth,fromHeight,toHeight);
         }else{
-            Logger.w(String.format("请正确传递change函数参数:x:%s;y:%s;width:%s;height:%s",
+            Logger.e(PARAM_ERROR,String.format("请正确传递change函数参数:x:%s;y:%s;width:%s;height:%s",
                     x,y,width,height));
+            return PARAM_ERROR;
         }
-
     }
 
     /*
     * 以动画形式改变播放器尺寸
     * */
-    private void animChanged(int fromX, int toX, int fromY, int toY, int fromWidth, int toWidth, int fromHeight, int toHeight) {
-        ValueAnimator animator = new ValueAnimator();
-        animator.setValues(
-                PropertyValuesHolder.ofFloat("x", fromX, toX),
-                PropertyValuesHolder.ofFloat("y", fromY, toY),
-                PropertyValuesHolder.ofInt("width", fromWidth, toWidth),
-                PropertyValuesHolder.ofInt("height", fromHeight, toHeight)
-        );
-        animator.setDuration(200);
-        animator.setInterpolator(new LinearInterpolator());
-        animator.addUpdateListener(valueAnimator -> {
-            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
-            params.width = (int) valueAnimator.getAnimatedValue("width");
-            params.height = (int) valueAnimator.getAnimatedValue("height");
-
-            baseMediaPlayer.setLayoutParams(params);
-
-            baseMediaPlayer.setX((Float) valueAnimator.getAnimatedValue("x"));
-            baseMediaPlayer.setY((Float) valueAnimator.getAnimatedValue("y"));
-        });
-        animator.start();
+    private int animChanged(int fromX, int toX, int fromY, int toY, int fromWidth, int toWidth, int fromHeight, int toHeight) {
+        try{
+            ValueAnimator animator = new ValueAnimator();
+            animator.setValues(
+                    PropertyValuesHolder.ofFloat("x", fromX, toX),
+                    PropertyValuesHolder.ofFloat("y", fromY, toY),
+                    PropertyValuesHolder.ofInt("width", fromWidth, toWidth),
+                    PropertyValuesHolder.ofInt("height", fromHeight, toHeight)
+            );
+            animator.setDuration(200);
+            animator.setInterpolator(new LinearInterpolator());
+            animator.addUpdateListener(valueAnimator -> {
+                FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
+                params.width = (int) valueAnimator.getAnimatedValue("width");
+                params.height = (int) valueAnimator.getAnimatedValue("height");
+
+                if(baseMediaPlayer != null){
+                    Logger.w("baseMediaPlayer is null,不能调用play函数");
+                }
+
+                baseMediaPlayer.setLayoutParams(params);
+
+                baseMediaPlayer.setX((Float) valueAnimator.getAnimatedValue("x"));
+                baseMediaPlayer.setY((Float) valueAnimator.getAnimatedValue("y"));
+            });
+            animator.start();
+            return SUCCESS;
+        }catch (Exception e){
+            e.printStackTrace();
+            return EXCEPTION_ERROR;
+        }
     }
 
 
     private void destroyVideo(){
-        if(baseMediaPlayer != null && baseMediaPlayer.getParent() != null){
-            release();
-            Activity activity = (Activity)context;
-            ViewGroup viewGroup = (ViewGroup) activity.getWindow().getDecorView();
-            viewGroup.removeView(baseMediaPlayer);
+        try{
+            if(baseMediaPlayer != null && baseMediaPlayer.getParent() != null){
+                release();
+                Activity activity = (Activity)context;
+                ViewGroup viewGroup = (ViewGroup) activity.getWindow().getDecorView();
+                viewGroup.removeView(baseMediaPlayer);
+            }
+        }catch (Exception e){
+            e.printStackTrace();
         }
     }
 }

+ 141 - 63
app/src/main/java/com/haochuan/hciptvbasic/webview/ToolToJS.java

@@ -2,6 +2,7 @@ package com.haochuan.hciptvbasic.webview;
 
 import android.app.Activity;
 import android.content.Context;
+import android.text.TextUtils;
 import android.webkit.JavascriptInterface;
 import android.webkit.WebView;
 
@@ -10,11 +11,19 @@ import com.haochuan.hciptvbasic.Util.DownloadUtils;
 import com.haochuan.hciptvbasic.Util.JsUtil;
 import com.haochuan.hciptvbasic.Util.Logger;
 import com.haochuan.hciptvbasic.Util.MacUtil;
+import com.haochuan.hciptvbasic.Util.MathUtil;
 import com.haochuan.hciptvbasic.Util.Md5Util;
 import com.haochuan.hciptvbasic.Util.ToolsUtil;
 
+import org.json.JSONObject;
+import org.w3c.dom.Text;
+
 import java.io.File;
 
+import static com.haochuan.hciptvbasic.Util.MessageCode.EXCEPTION_ERROR;
+import static com.haochuan.hciptvbasic.Util.MessageCode.PARAM_ERROR;
+import static com.haochuan.hciptvbasic.Util.MessageCode.SUCCESS;
+
 
 public class ToolToJS {
     private Context context;                        //MainActivity 句柄
@@ -101,6 +110,21 @@ public class ToolToJS {
         return toolsUtil.getIntentJson(context);
     }
 
+    @JavascriptInterface
+    public String getLocalParamsByJson(){
+        try{
+            JSONObject localParamsJson = new JSONObject();
+            localParamsJson.put("version_code",BuildConfig.VERSION_CODE);
+            localParamsJson.put("version_name",BuildConfig.VERSION_NAME);
+            localParamsJson.put("mac",MacUtil.getMac(context) != null ? MacUtil.getMac(context) : "");
+            localParamsJson.put("intent_json",new JSONObject(toolsUtil.getIntentJson(context)));
+            return localParamsJson.toString();
+        }catch (Exception e){
+            e.printStackTrace();
+            return "";
+        }
+    }
+
     /*-----------------------------操作APK-------------------------------------*/
 
     /**
@@ -109,49 +133,72 @@ public class ToolToJS {
      * 返回 0,安装;-1,未安装
      * **/
     @JavascriptInterface
-    public int checkAppInstalled(String packageName){
-        return toolsUtil.checkSubAppInstalled(context,packageName)?0:-1;
+    public int checkAppInstalled(String paramsJson){
+        try{
+            JSONObject jsonObject = new JSONObject(paramsJson);
+            String packageName = jsonObject.has("package_name")?jsonObject.get("package_name").toString():"";
+            return toolsUtil.checkSubAppInstalled(context,packageName)?0:-1;
+        }catch (Exception e){
+            e.printStackTrace();
+            return -1;
+        }
     }
 
-
-
     /*
     * 下载
     * */
     @JavascriptInterface
-    public void download(String downloadUrl){
-        DownloadUtils.download(downloadUrl, context.getPackageName() + getVersionCode(), "apk", new DownloadUtils.DownloadProgressListener() {
-            @Override
-            public void onDownloadStart(String fileName) {
-                JsUtil.evaluateJavascript(context,webView,JS_EVENT_DOWNLOAD_START);
-            }
-
-            @Override
-            public void onDownloadProgress(int progress) {
-                JsUtil.evaluateJavascript(context,webView,
-                        String.format(JS_EVENT_DOWNLOAD_PROGRESS,progress));
+    public int download(String paramsJson){
+        try{
+            JSONObject jsonObject = new JSONObject(paramsJson);
+            String downloadUrl = jsonObject.has("download_url")?jsonObject.get("download_url").toString():"";
+            if(TextUtils.isEmpty(downloadUrl)){
+                Logger.e(PARAM_ERROR,"download_url is empty,download stopped");
+                return PARAM_ERROR;
             }
+            DownloadUtils.download(downloadUrl, context.getPackageName() + getVersionCode(), "apk", new DownloadUtils.DownloadProgressListener() {
+                @Override
+                public void onDownloadStart(String fileName) {
+                    JsUtil.evaluateJavascript(context,webView,JS_EVENT_DOWNLOAD_START);
+                }
+
+                @Override
+                public void onDownloadProgress(int progress) {
+                    JsUtil.evaluateJavascript(context,webView,
+                            String.format(JS_EVENT_DOWNLOAD_PROGRESS,progress));
+                }
 
-            @Override
-            public void onDownloadSuccessful(String filePath) {
-                JsUtil.evaluateJavascript(context,webView,
-                        String.format(JS_EVENT_DOWNLOAD_SUCCESS,filePath));
-            }
+                @Override
+                public void onDownloadSuccessful(String filePath) {
+                    JsUtil.evaluateJavascript(context,webView,
+                            String.format(JS_EVENT_DOWNLOAD_SUCCESS,filePath));
+                }
 
-            @Override
-            public void onDownloadFail(String message){
-                JsUtil.evaluateJavascript(context,webView,
-                        String.format(JS_EVENT_DOWNLOAD_FAIL,message));
-            }
-        });
+                @Override
+                public void onDownloadFail(String message){
+                    JsUtil.evaluateJavascript(context,webView,
+                            String.format(JS_EVENT_DOWNLOAD_FAIL,message));
+                }
+            });
+            return SUCCESS;
+        }catch (Exception e){
+            e.printStackTrace();
+            return EXCEPTION_ERROR;
+        }
     }
 
     /*
     * 获得下载文件MD5值
     * */
     @JavascriptInterface
-    public String getMD5(String filePath){
+    public String getMD5(String paramsJson){
         try{
+            JSONObject jsonObject = new JSONObject(paramsJson);
+            String filePath = jsonObject.has("file_path")?jsonObject.get("file_path").toString():"";
+            if(TextUtils.isEmpty(filePath)){
+                Logger.e(PARAM_ERROR,"file_path is empty,getMD5 function stopped");
+                return "";
+            }
             return Md5Util.getFileMD5(new File(filePath));
         }catch (Exception e){
             e.printStackTrace();
@@ -161,53 +208,59 @@ public class ToolToJS {
 
     /**
      * 安装app
-     * @param apkPath 本地安装包路径
      */
     @JavascriptInterface
-    public void install(String apkPath) {
-        ((Activity) context).runOnUiThread(() -> toolsUtil.installApk(context,apkPath));
+    public int install(String paramsJson) {
+        try{
+            JSONObject jsonObject = new JSONObject(paramsJson);
+            String filePath = jsonObject.has("file_path")?jsonObject.get("file_path").toString():"";
+            if(TextUtils.isEmpty(filePath)){
+                Logger.e(PARAM_ERROR,"file_path is empty,install function stopped");
+                return PARAM_ERROR;
+            }
+            ((Activity) context).runOnUiThread(() -> toolsUtil.installApk(context,filePath));
+            return SUCCESS;
+        }catch (Exception e){
+            e.printStackTrace();
+            return EXCEPTION_ERROR;
+        }
     }
 
-
-
     /**
      * 卸载app
      */
     @JavascriptInterface
-    public void uninstall(String pkgName) {
-        ((Activity) context).runOnUiThread(() -> toolsUtil.uninstall(context,pkgName));
+    public int uninstall(String paramsJson) {
+        try{
+            JSONObject jsonObject = new JSONObject(paramsJson);
+            String packageName = jsonObject.has("package_name")?jsonObject.get("package_name").toString():"";
+            ((Activity) context).runOnUiThread(() -> toolsUtil.uninstall(context,packageName));
+            return SUCCESS;
+        }catch (Exception e){
+            e.printStackTrace();
+            return EXCEPTION_ERROR;
+        }
     }
 
     /*
      * 退出app
      * */
     @JavascriptInterface
-    public void appExit(){
-        ((Activity) context).runOnUiThread(() -> {
-            android.os.Process.killProcess(android.os.Process.myPid());   //获取PID
-            System.exit(0);
-        });
+    public int appExit(){
+        try{
+            ((Activity) context).runOnUiThread(() -> {
+                android.os.Process.killProcess(android.os.Process.myPid());   //获取PID
+                System.exit(0);
+            });
+            return SUCCESS;
+        }catch (Exception e){
+            e.printStackTrace();
+            return EXCEPTION_ERROR;
+        }
     }
 
     /*---------------------------通过客户端请求接口------------------------*/
 
-    /*
-     *js 通过apk客户端访问网络接口
-     *@param paramJson 请求参数集,格式为json字符串
-     *@param headJson 请求头部集,格式为json字符串
-     *@param method 请求方法,1,get;2,post
-     *@param ignoreResult 是否忽略结果,true,忽略;false,不忽略.
-     *@param tag 透传参数,将在结果回调中一并返回,主要区别多个并发请求
-     * */
-    @JavascriptInterface
-    public void clientWebRequest(String url,int method,String paramJson,String headJson,boolean ignoreResult,String tag){
-        toolsUtil.clientWebRequest(url,method, paramJson, headJson,  ignoreResult, tag,
-                (int what,String response,String tag1)->{
-                    Logger.d(String.format("what:%s,response:%s;tag:%s",what,response,tag1));
-                    JsUtil.evaluateJavascript(context,webView,
-                            String.format(JS_EVENT_RESPONSE,what,response,tag1));
-                });
-    }
 
 
     /*
@@ -220,13 +273,38 @@ public class ToolToJS {
      *@param tag 透传参数,将在结果回调中一并返回,主要区别多个并发请求
      * */
     @JavascriptInterface
-    public void clientWebRequest(String url,int method,String contentType,String paramJson,String headJson,boolean ignoreResult,String tag){
-        toolsUtil.clientWebRequest(url, method, contentType, headJson,paramJson, ignoreResult, tag,
-                (int what,String response,String tag1)->{
-                    Logger.d(String.format("what:%s,response:%s;tag:%s",what,response,tag1));
-                    JsUtil.evaluateJavascript(context,webView,
-                            String.format(JS_EVENT_RESPONSE,what,response,tag1));
-                });
+    public int clientWebRequest(String paramsJson){
+        try{
+            JSONObject requestParams = new JSONObject(paramsJson);
+            String url = requestParams.has("url")?requestParams.get("url").toString():"";
+            String methodStr = requestParams.has("method")?requestParams.get("method").toString():"1";
+            int method = 0;
+            if(MathUtil.isDigitsOnly(methodStr)){
+                method = Integer.parseInt(methodStr);
+                if( method <0  || method > 1 ){
+                    Logger.w("clientWebRequest 请求参数method必须为0或者1,目前重置为0");
+                    method = 0;
+                }
+            }else{
+                Logger.w("clientWebRequest 请求参数method必须为数字,目前重置为0");
+            }
+            String contentType = requestParams.has("content_type")?requestParams.get("content_type").toString():"application/json";
+            String headJson = requestParams.has("head_json")?requestParams.get("head_json").toString():"{}";
+            String paramJson = requestParams.has("param_json")?requestParams.get("param_json").toString():"{}";
+            String ignore = requestParams.has("ignore_result")?requestParams.get("ignore_result").toString():"0";
+            boolean ignoreResult = TextUtils.equals(ignore,"1");
+            String tag = requestParams.has("tag")?requestParams.get("tag").toString():"";
+            toolsUtil.clientWebRequest(url, method, contentType, headJson,paramJson, ignoreResult, tag,
+                    (int what,String response,String tag1)->{
+                        Logger.d(String.format("what:%s,response:%s;tag:%s",what,response,tag1));
+                        JsUtil.evaluateJavascript(context,webView,
+                                String.format(JS_EVENT_RESPONSE,what,response,tag1));
+                    });
+            return SUCCESS;
+        }catch (Exception e){
+            e.printStackTrace();
+            return EXCEPTION_ERROR;
+        }
     }
 
 }