android


Android Multiple Button Press


How to make when press multiple keys at same time (like when booting recovery and download mode using power and volume keys) start new activity in android application?
#Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN))
{
Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
}
return true;
}
Try the following solution, it is tested and it works!
public class MainActivity extends AppCompatActivity {
private boolean isVolumeUpPressed = false;
private boolean isVolumeDownPressed = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
this.isVolumeDownPressed = true;
} else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
this.isVolumeUpPressed = true;
}
if (this.isVolumeUpPressed && this.isVolumeDownPressed) {
final Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
}
return super.onKeyUp(keyCode, event);
}
#Override
public boolean onKeyUp(final int keyCode, final KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
this.isVolumeDownPressed = false;
} else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
this.isVolumeUpPressed = false;
}
return super.onKeyUp(keyCode, event);
}
}
if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) && (keyCode == KeyEvent.KEYCODE_VOLUME_UP)) {

Related Links

android: I fetch node with attribute how can i get its child nodes
Move SurfaceView in Android
android Json show only last item
How to make an extension app which provide resource for a main app
How do you fire onItemClickListener when you also have onTouchListener?
EditText appears in front of listview items
surfaceCreated is not called and so thread does not start
Pass EditText Value to Another Activity with Same Style in Android
VM aborting when starting new activity
android: Canvas.drawColor(Color.BLACK) doesn't work to clear canvas
Android backup/restore sample doesn't work?
Screen Dimensions Being Calculated Incorrectly
Android AsyncTask boolean changes to false after new page is loaded
Is it counted as in-app payment if Paypal cart is opened as web page?
Runtime Exception while launching android app
Can't get any thread in DDMS window when debugging

Categories

HOME
url-redirection
phpword
turing-machines
cobalt
telegram
jmeter
interface
mstest
package
owl-carousel
aws-cli
missing-data
banner
recordrtc
elasticsearch-5
teechart
project-intu
mautic
angular-dart
symbol
altera
alpacajs
esoteric-languages
atlassian-stash
apache2.4
visual-glitch
jquery-ias
php-mysqlidb
roundup
dapper-extensions
custom-post-type
oculus
inversion-of-control
deltaspike
instantiation
lubridate
hivemq
reason
filesystemwatcher
naming
microsoft-metro
outputcache
signal-strength
servermanager
nanoc
netbeans6.8
openblas
trojan
singleinstance
cvxpy
taocp
stripe-connect
winusb
redbeard-ios
swizzling
stream-processing
hadoop-partitioning
html-to-pdf
libav
crouton-os
concurrentmodification
custom-errors
toran-proxy
qt5.2
poppler
zscript
sha512
google-refine
mraid
cakephp-2.7
showdialog
viewer
jqmodal
ss7
android-framework
amslidemenu
drupal-nodes
sbcl
bin
time.h
apache-abdera
bjyauthorize
fragmenttransaction
extconf.rb
httponly
isa-swizzling
listactivity
socketserver
binomial-heap
zen
alsb

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App