2017-09-27 1 views
0

Ich baue eine Android-App mit Cordova. Diese App wird auf einem robusten Scanner verwendet, der eine physikalische numerische Tastatur erhält. Mein Problem ist, wenn ich den Fokus auslöst, wird das Softkeyboard ausgelöst.Cordova Android deaktivieren Softkeyboard

Vorerst Ich habe versucht, ein Plugin, um das Softkeyboard zu aktivieren/deaktivieren:

/** 
package com.example; 

import android.app.Activity; 
import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 
import android.content.IntentFilter; 
import android.view.View; 
import android.view.inputmethod.InputMethodManager; 

import org.apache.cordova.CallbackContext; 
import org.apache.cordova.CordovaInterface; 
import org.apache.cordova.CordovaPlugin; 
import org.apache.cordova.CordovaWebView; 
import org.json.JSONArray; 
import org.json.JSONException; 
import org.json.JSONObject; 

public class KeyboardPlugin extends CordovaPlugin { 

    private View mView; 
    private Context mCordova; 
    private Boolean status; 

    @Override 
    public void initialize (CordovaInterface cordova, CordovaWebView webView) { 
    mView = webView.getView(); 
    mCordova = cordova.getActivity().getApplicationContext(); 
    } 

    @Override 
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { 
    InputMethodManager imm = (InputMethodManager)mCordova.getSystemService(Context.INPUT_METHOD_SERVICE ); 
    if (action.equals("enable")) { 
     status = true; 
     imm.hideSoftInputFromWindow(mView.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY); 
    } else if (action.equals("disable")){ 
     status = false; 
     imm.hideSoftInputFromWindow(mView.getWindowToken(), 0); 
    } 
    return false; 
    } 
} 

Hat jemand schon das zu tun? Es gibt einige Thread darüber, aber sie alle sind wirklich alt mit der alten Version von Android und Cordova.

Es gibt keinen Fehler, es macht einfach nichts.

Antwort

0

Ich habe ein Plugin, das die gleiche Funktionalität implementiert. Sie können den Code here sehen.

Activity activity = this.cordova.getActivity(); 
InputMethodManager imm = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE); 

View view; 
try { 
    view = (View)webView.getClass().getMethod("getView").invoke(webView); 
} 
catch (Exception e){ 
    view = (View)webView; 
} 

if("hide".equals(action)){ 
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0); 
    callbackContext.success(); 
    return true; 
} 
callbackContext.error(action + " is not a supported action"); 
return false; 

Der einzige große Unterschied sehe ich zwei Möglichkeiten, zwei statt Instanzvariable die Ansicht ist und die Ansicht als lokal bekommen. Funktioniert die Verwendung dieses Codes für Sie?

Verwandte Themen