9

キーをタップしたときにキーボードの音と振動を無効および有効にする方法を見つけようとしています。Stack Overflowや他のAndroid フォーラムを検索しましたが、結果が見つかりませんでした。

バイブレーションモードを有効にしようとしましAudioManagerたが、バイブレーションモードとキーボードの音を有効にしたいです。

audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, 
                AudioManager.VIBRATE_SETTING_ON);

android.provider.Settingsキーボードの音とバイブレーションを変更する方法はありますか?

4

3 に答える 3

4

あなたのコメントによると:

私はAndroidのデフォルトのキーボードについて話しているのですが、ユーザーがキーボードのキーをタップしたときにキーボードの音と振動を無効/有効にする機能が必要です(キーボードの設定のように)

&

SAMSUNG GALAXY S2 や HTC ONE などのソフト キーボードについて話しています。

私の知る限り、各入力方法はその音/振動の設定値を内部的に保持するため、これを達成することはできません。たとえば、Android (AOSP) IMeを参照してください(これを書いている時点で 30 ~ 39 行目):

    <CheckBoxPreference
        android:key="vibrate_on"
        android:title="@string/vibrate_on_keypress"
        android:defaultValue="@bool/config_default_vibration_enabled"
        android:persistent="true" />
    <CheckBoxPreference
        android:key="sound_on"
        android:title="@string/sound_on_keypress"
        android:defaultValue="@bool/config_default_sound_enabled"
        android:persistent="true" />

ご覧のとおり、振動/音の値は共有設定に保存されます。これは、市場に出回っているほとんどの IMe に当てはまります。したがって、一点からすべての IMe の振動/効果音を制御することはできません。

于 2013-05-15T07:47:16.927 に答える
0

はい、root アクセス権があれば実行できます。その長いプロセスですが、これを行うことができます:

ステップ : 1 という名前の xml ファイルを作成com.android.inputmethod.latin_preferences.xmlし、assets に保存します。

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="false" />
</map>

ステップ 2 : このファイルをアプリケーション フォルダ (アクセスできる場所ならどこでも) にコピーしますasset manager

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

この関数はアセットからファイルをコピーします

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 : デバイスを再起動する

これですべて完了です。これらのステップは、キーを押す音とキーを押す振動をオフにします

于 2017-11-02T13:49:03.697 に答える