There is an application that should, when you press a physical button, switch the phone from vibro to normal and vice versa. How to reassign the press, so that this business works after the closure of the activity and even when the screen is off?
Now I have it all work with activity.
public class MainActivity extends AppCompatActivity { AudioManager am; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); am = (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE); AppStart(); } public void AppStart() { if (am.getRingerMode() == RINGER_MODE_NORMAL) { am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); } else { am.setRingerMode(AudioManager.RINGER_MODE_NORMAL); } } public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == (KeyEvent.KEYCODE_NOTIFICATION)) { AppStart(); return true; } return false; } }