@Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { instance = this; this.appId = getAppId(); this.api = WXAPIFactory.createWXAPI(webView.getContext(), this.appId, true); this.api.registerApp(this.appId); // 将App注册到微信列表 }
/** * Create a new plugin result and send it back to JavaScript * * @param connection status */ private void sendStatusUpdate(boolean isConnected) { final Intent intent = new Intent("DatecsPrinter.connectionStatus"); Bundle b = new Bundle(); b.putString("userdata", "{ isConnected: " + isConnected + "}"); intent.putExtras(b); LocalBroadcastManager.getInstance(mWebView.getContext()).sendBroadcastSync(intent); }
protected void init() { webView = makeWebView(); createViews(); if (!webView.isInitialized()) { webView.init(cordovaInterface, pluginEntries, preferences); } webView.getView().requestFocusFromTouch(); cordovaInterface.onCordovaInit(webView.getPluginManager()); // webView.clearCache(); android.webkit.CookieManager.getInstance().removeAllCookie(); // Wire the hardware volume controls to control media if desired. String volumePref = preferences.getString("DefaultVolumeStream", ""); if ("media".equals(volumePref.toLowerCase(Locale.ENGLISH))) { getActivity().setVolumeControlStream(AudioManager.STREAM_MUSIC); } BaseActivity activity = (BaseActivity) getActivity(); activity.hideToolbar(2); gestureDetector = new GestureDetector(webView.getContext(), this); webView.getView().setOnTouchListener(this); }
/** * Sets the context of the Command. This can then be used to do things like get file paths * associated with the Activity. * * @param cordova The context of the main Activity. * @param webView The CordovaWebView Cordova is running in. */ public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); this.sockMan = (ConnectivityManager) cordova.getActivity().getSystemService(Context.CONNECTIVITY_SERVICE); this.connectionCallbackContext = null; // We need to listen to connectivity events to update navigator.connection IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); if (this.receiver == null) { this.receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // (The null check is for the ARM Emulator, please use Intel Emulator for better // results) if (NetworkManager.this.webView != null) updateConnectionInfo(sockMan.getActiveNetworkInfo()); } }; webView.getContext().registerReceiver(this.receiver, intentFilter); } }