sdk需要獲取sdk之外的參數,方法,甚至Class?

1。 需要外部參數
可以用構造函數,或者set方法,在初始化的時候進行

2。需要外部方法
用回調方法實現


   //兩個回調接口,分別用於拉取全局控制數據和單個activity的配置數據
    public interface SyncConfigDataCallback
    {
        public JSONArray downloadGlobalData();
        public JSONArray downloadPageData(String pageName);
    }
    public static SyncConfigDataCallback mSyncConfigDataCallback;

    public static void setSyncConfigDataCallback(SyncConfigDataCallback SyncConfigDataCallback)
    {
        mSyncConfigDataCallback = SyncConfigDataCallback;
    }

    //在BifrostConfig中調用,用於全局參數的配置獲取
    public static void updateGlobalConfigData()
    {
            globalConfigJson = BFConfigCenterData.mSyncConfigDataCallback.downloadGlobalData();
//            Log.d("tingxiang global config","  "+globalConfigJson.length());
            if (globalConfigJson.length() > 0) {
                globalConfigData = new BFGlobalConfigModuleList(globalConfigJson);
            }

    }
  BFConfigCenterData.setSyncConfigDataCallback(new BFConfigCenterData.SyncConfigDataCallback() {
                    @Override
                    public JSONArray downloadGlobalData() {
                        JSONArray jsonData = null;
                        jsonData = TMConfigCenterManager.getInstance().getConfigDataArray("Bifrost");
                        return jsonData;
                    }

                    @Override
                    public JSONArray downloadPageData(String pageName) {
                        JSONArray jsonData = null;
                        jsonData = TMConfigCenterManager.getInstance().getConfigDataArray("bifrost_" + pageName);
                        return jsonData;
                    }
                });

3。 需要用到外部定義的class
註冊外部類的class路徑,在sdk中可根據這個路徑找到這個類,注意在android 6。0的手機上,必須調用RegisterInvoker.getDeclaredConstructor().setAccessible(true);
否則會有權限問題

註冊:

    BFInvokerMgr.registerBFInvoker(BFConstant.EVENT_SCREENSHOT_FEEDBACK, "com.tmall.wireless.application.bifrostinvoker.BFInvokerFeedback");
                BFInvokerMgr.registerBFInvoker(BFConstant.EVENT_JUMP_URL, "com.tmall.wireless.application.bifrostinvoker.BFInvokerJumpUrl");

根據類名尋找,新建類對象

 BFInvoker invoker = null;
            Class RegisterInvoker = null;
            try {
                RegisterInvoker = Class.forName(registeredInvokerClass.get(invokerType));
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            try {
                RegisterInvoker.getDeclaredConstructor().setAccessible(true);
              invoker =  (BFInvoker) RegisterInvoker.newInstance();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            }
            return invoker;
發佈了74 篇原創文章 · 獲贊 3 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章