2013-03-14 1 views
6

という入力メソッドを実装しています。RemoteInputは、InputViewとキーボードを使用せずにInputMethodServiceを拡張するだけです。ユーザーがRemoteInputをデフォルトのIMEとして選択すると、RemoteInputは現在の入力ステータスを他のデバイスに送信し、ユーザーは遠隔から入力アクションを行うことができます。入力が完了すると、他のデバイスに入力されたテキストが現在のデバイスに返され、RemoteInputはInputConnection.commitText (CharSequence text, int newCursorPosition)を使用して現在のUIコンポーネント(EditTextなど)にテキストをコミットします。InputConnection.commitText(CharSequence text、int newCursorPosition)は英語の文字と数字のみをコミットできますか?

リモート入力のテキストが英語の文字と数字の場合は理想的ですが、他の文字の場合は正しく表示されません。私はInputConnection.commitText他の文字をフィルタしています。たとえば、私はhello你好と入力し、helloだけが正常にコミットされます。そして、もっと:

  • hello world ==>helloworld
  • hello,world!! ==>あなたはこのことについて教えてhelloworld

ものは、事前に感謝参考になります。

は、ここに私のコードです:

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(); 
    } 
} 

答えて

-2

あなたはUnicodeを使用するために必要とされる英語以外の言語を使用している場合。ユニコードフォントをプロジェクトに添付し、要素の書体(EditTextなど)を添付したフォントに設定する必要があります。アプリにカスタムフォントを追加する方法については、以下を参照してください。

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

2番目のオプションは、お使いのデバイスを根絶し、必要なフォントをインストールすることです。

関連する問題