2013-03-14 5 views
6

Implemento un metodo di immissione denominato RemoteInput estendere semplicemente InputMethodService, senza InputViews e senza tastiere. Quando l'utente seleziona RemoteInput come IME predefinito, RemoteInput invierà lo stato di input corrente ad altro dispositivo e l'utente può eseguire l'azione di input da remoto (utilizzando il nostro protocollo customerized). Al termine dell'input, il testo immesso in un altro dispositivo verrà rinviato al dispositivo corrente, quindi RemoteInput commetterà il testo sul componente UI corrente (come EditText) utilizzando InputConnection.commitText (CharSequence text, int newCursorPosition).InputConnection.commitText (testo CharSequence, int newCursorPosition) può solo memorizzare caratteri e numeri inglesi?

Funziona perfettamente quando il testo in ingresso remoto è composto da caratteri e numeri inglesi, ma quando si tratta di altri personaggi le cose vanno male. Ho trovato che il filtro InputConnection.commitText altri caratteri. Ad esempio, ho inserito hello你好, solo hello essere stato eseguito correttamente. E ancora:

  • hello world ==>helloworld
  • hello,world!! ==>helloworld

Tutto ciò che si parli di questo sarà utile, grazie in anticipo.

Ecco il mio codice:

public class RemoteInput extends InputMethodService { 
    protected static String TAG = "RemoteInput"; 

    public static final String ACTION_INPUT_REQUEST = "com.aidufei.remoteInput.inputRequest"; 
    public static final String ACTION_INPUT_DONE = "com.aidufei.remoteInput.inputDone"; 

    private BroadcastReceiver mInputReceiver = new BroadcastReceiver() { 

     @Override 
     public void onReceive(Context context, Intent intent) { 
      if (ACTION_INPUT_DONE.equals(intent.getAction())) { 
       String text = intent.getStringExtra("text"); 
       Log.d(TAG, "broadcast ACTION_INPUT_DONE, input text: " + text); 
       input(text); 
      } 
     } 
    }; 

    @Override 
    public void onCreate() { 
     super.onCreate(); 

     registerReceiver(mInputReceiver, new IntentFilter(ACTION_INPUT_DONE)); 
    } 

    @Override 
    public View onCreateInputView() { 
     //return getLayoutInflater().inflate(R.layout.input, null); 
     return null; 
    } 

    @Override 
    public boolean onShowInputRequested(int flags, boolean configChange) { 
     if (InputMethod.SHOW_EXPLICIT == flags) { 
      Intent intent = new Intent(ACTION_INPUT_REQUEST); 
      getCurrentInputConnection().performContextMenuAction(android.R.id.selectAll); 
      CharSequence text = getCurrentInputConnection().getSelectedText(0); 
      intent.putExtra("text", text==null ? "" : text.toString()); 
      sendBroadcast(intent); 
     } 
     return false; 
    } 

    public void input(String text) { 
     InputConnection inputConn = getCurrentInputConnection(); 
     if (text != null) { 
      inputConn.deleteSurroundingText(100, 100); 
      inputConn.commitText(text, text.length()); 
     } 
     //inputConn.performEditorAction(EditorInfo.IME_ACTION_DONE); 
    } 

    @Override 
    public void onDestroy() { 
     unregisterReceiver(mInputReceiver); 
     super.onDestroy(); 
    } 
} 

risposta

-2

Se si utilizza una lingua diversa dall'inglese si sono tenuti a utilizzare Unicode. Devi allegare il tuo font Unicode al tuo progetto e impostare il carattere tipografico dell'elemento (ad esempio EditText) sul carattere che hai allegato. Vedi quanto segue per scoprire come aggiungere caratteri personalizzati alla tua app.

http://tharindudassanayake.wordpress.com/2012/02/25/use-sinhala-fonts-for-your-android-app/

La seconda opzione sarebbe quella di radicare il dispositivo e installare il carattere richiesto.

Problemi correlati