2016-07-14 13 views
0

私はアンドロイド用のカスタムキーボードを作成しています。私のキーボードのキーを押すと、私は欲しいものが、アンドロイドソフトキーボードのようなタッチで振動することです。私はこの回答enable/disable keyboard sound and vibration programmaticallyを参照しても、私はそれを使用する方法を理解できませんでした。誰でも私のカスタムキーボードアプリでこの機能を利用する方法を説明できますか?android soft keyboardのkeypressの振動

答えて

0
audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); 

マニフェストに振動を含めることを忘れないでください。

0

はい、ルートアクセス権がある場合は、これを行うことができます。その長いプロセスですが、これを行うことができます:

手順:1 com.android.inputmethod.latin_preferences.xmlという名前のxmlファイルを作成し、アセットに保存します。

com.android.inputmethod.latin_preferences.xml

<?xml version='1.0' encoding='utf-8' standalone='yes' ?> 
<map> 
    <boolean name="popup_on" value="false" /> 
    <string name="auto_correction_threshold">1</string> 
    <boolean name="pref_enable_metrics_logging" value="true" /> 
    <boolean name="pref_voice_input_key" value="true" /> 
    <boolean name="pref_key_use_personalized_dicts" value="true" /> 
    <boolean name="pref_key_block_potentially_offensive" value="true" /> 
    <int name="last_shown_emoji_category_id" value="1" /> 
    <boolean name="sound_on" value="false" /> 
    <string name="emoji_recent_keys">[{&quot;Integer&quot;:128533}]</string> 
    <boolean name="auto_cap" value="true" /> 
    <boolean name="show_suggestions" value="true" /> 
    <boolean name="pref_key_use_contacts_dict" value="true" /> 
    <boolean name="next_word_prediction" value="true" /> 
    <boolean name="pref_key_use_double_space_period" value="true" /> 
    <int name="emoji_category_last_typed_id1" value="0" /> 
    <boolean name="vibrate_on" value="true" /> 
</map> 

ステップ2:あなたは、この機能からファイルをコピーします

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

を必要とするためasset managerを使用してアプリケーションフォルダ(あなたがアクセスできるどこでも)にこのファイルをコピーします。資産

public static void copyAssets(Context context, String assetPath, String outFilename) { 
     AssetManager assetManager = context.getAssets(); 
     InputStream in = null; 
     OutputStream out = null; 
     try { 
      in = assetManager.open(assetPath); 
      File outFile = new File(context.getExternalFilesDir(null), outFilename); 

      out = new FileOutputStream(outFile); 
      copyFile(in, out); 
     } catch (IOException e) { 
      Log.e(TAG, "Failed to copy asset: " + outFilename, e); 
     } finally { 
      if (in != null) { 
       try { 
        in.close(); 
       } catch (IOException e) { 
       } 
      } 
      if (out != null) { 
       try { 
        out.close(); 
       } catch (IOException e) { 
       } 
      } 
     } 
    } 

public static void copyFile(InputStream in, OutputStream out) throws IOException { 
     byte[] buffer = new byte[1024]; 
     int read; 
     while ((read = in.read(buffer)) != -1) { 
      out.write(buffer, 0, read); 
     } 
    } 

ステップ3:再起動デバイス全て行うの

:システム環境のファイルシステムパスを上書き(DESTPATH)は/data/data/com.android.inputmethod.latin/shared_prefs

public static void copyToSystem(final String sourceFilePath, final String destPath) { 
     Thread background = new Thread(new Runnable() { 

      @Override 
      public void run() { 
       try { 
        Process process = Runtime.getRuntime().exec("su"); 
        DataOutputStream os = new DataOutputStream(process.getOutputStream()); 
//      
        os.writeBytes("cp -f " + sourceFilePath + " " + destPath + "\n"); 
        os.flush(); 
        os.writeBytes("exit\n"); 
        os.flush(); 
        process.waitFor(); 
        process.waitFor(); 
       } catch (InterruptedException e) { 
        e.printStackTrace(); 
        Log.e(TAG, e.toString()); 
       } catch (IOException e) { 
        e.printStackTrace(); 
        Log.e(TAG, e.toString()); 
       } 
      } 
     }); 
     background.start(); 
    } 

ステップ4です。これらのステップにより、キー押さえ音が無効になり、キー押さえ振動が可能になります。